Skip to content

Commit

Permalink
Merge pull request #377 from sensu/github-token-changes
Browse files Browse the repository at this point in the history
Github token authentication issue fix
  • Loading branch information
chavakula authored Jan 14, 2025
2 parents 57cfe58 + d31d80d commit f5f9051
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion app/interactors/compile_github_extension_version_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def read_sha_file(compiled_sha_filename, asset_filename, github_asset_data_hashe
sha_download_url = asset_data(compiled_sha_filename, github_asset_data_hashes_lut)[:url]
result = FetchRemoteSha.call(
sha_download_url: sha_download_url,
sha_download_auth_token: version.github_oauth_token(current_user),
asset_filename: asset_filename
)

Expand Down
4 changes: 2 additions & 2 deletions app/interactors/concerns/reads_github_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def gather_github_release_asset_data_hashes(version)
Array.wrap(releases_data[:assets])
end

def read_github_file(url, auth_token)
def read_github_file(url)
return nil unless url.present?

faraday = Faraday.new { |f|
f.use FaradayMiddleware::FollowRedirects
f.adapter :net_http
f.basic_auth('x-oauth-basic', auth_token) if auth_token.present?
f.basic_auth(ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"])
f.headers['Accept'] = 'application/octet-stream'
}

Expand Down
3 changes: 1 addition & 2 deletions app/interactors/fetch_remote_sha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ class FetchRemoteSha
# The required context attributes:
delegate :asset_filename, to: :context
delegate :sha_download_url, to: :context
delegate :sha_download_auth_token, to: :context

def call
sha_file_content = read_github_file(sha_download_url, sha_download_auth_token)
sha_file_content = read_github_file(sha_download_url)
sha = extract_sha_for_binary(asset_filename, sha_file_content)

context.sha = sha
Expand Down
4 changes: 2 additions & 2 deletions app/interactors/persist_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def call

def mirror_to_s3(release_asset, url, auth_token)
key = release_asset.destination_pathname
object_exists = s3_bucket.object(key).exists?

object_exists = s3_bucket.object(key)
if object_exists
# we need to replace the file each iteration in order
# to update files in case they were changed.
Expand All @@ -61,7 +61,7 @@ def mirror_to_s3(release_asset, url, auth_token)

# get file contents
begin
file = read_github_file(url, auth_token)
file = read_github_file(url)
rescue => error
puts "****** file read error: #{error}"
return
Expand Down
1 change: 0 additions & 1 deletion app/models/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ def is_valid_github_token?(token)

def octokit_client(auth_token)
Octokit::Client.new(
access_token: auth_token,
client_id: Rails.configuration.octokit.client_id,
client_secret: Rails.configuration.octokit.client_secret
)
Expand Down
7 changes: 4 additions & 3 deletions app/workers/sync_extension_contents_at_versions_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,11 @@ def scan_config_yml_file(version, current_user, system_command_runner=@run)
version: version,
system_command_runner: system_command_runner
)

if compilation_result.success? && compilation_result.data_hash.present? && compilation_result.data_hash.is_a?(Hash)
version.update_columns(
config: compilation_result.data_hash,
compilation_error: nil
version.update(
config: compilation_result.data_hash,
compilation_error: nil
)
elsif compilation_result.error.present?
version.update_column(:compilation_error, compilation_result.error)
Expand Down

0 comments on commit f5f9051

Please sign in to comment.