From d31d80d8b5bfe5e0abba7e4382b80648d1bf4d62 Mon Sep 17 00:00:00 2001 From: Rajshekar Chavakula Date: Tue, 14 Jan 2025 10:51:26 +0530 Subject: [PATCH] Github token changes --- app/interactors/compile_github_extension_version_config.rb | 1 - app/interactors/concerns/reads_github_files.rb | 4 ++-- app/interactors/fetch_remote_sha.rb | 3 +-- app/interactors/persist_assets.rb | 4 ++-- app/models/extension.rb | 1 - app/workers/sync_extension_contents_at_versions_worker.rb | 7 ++++--- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/interactors/compile_github_extension_version_config.rb b/app/interactors/compile_github_extension_version_config.rb index 20c72183..1b2ad372 100755 --- a/app/interactors/compile_github_extension_version_config.rb +++ b/app/interactors/compile_github_extension_version_config.rb @@ -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 ) diff --git a/app/interactors/concerns/reads_github_files.rb b/app/interactors/concerns/reads_github_files.rb index 0de96c08..8fd1d24c 100644 --- a/app/interactors/concerns/reads_github_files.rb +++ b/app/interactors/concerns/reads_github_files.rb @@ -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' } diff --git a/app/interactors/fetch_remote_sha.rb b/app/interactors/fetch_remote_sha.rb index 3a2cce3a..8b77e395 100755 --- a/app/interactors/fetch_remote_sha.rb +++ b/app/interactors/fetch_remote_sha.rb @@ -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 diff --git a/app/interactors/persist_assets.rb b/app/interactors/persist_assets.rb index 1cfd4f36..a7cfd65b 100755 --- a/app/interactors/persist_assets.rb +++ b/app/interactors/persist_assets.rb @@ -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. @@ -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 diff --git a/app/models/extension.rb b/app/models/extension.rb index 8001fed8..cfe4e30b 100755 --- a/app/models/extension.rb +++ b/app/models/extension.rb @@ -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 ) diff --git a/app/workers/sync_extension_contents_at_versions_worker.rb b/app/workers/sync_extension_contents_at_versions_worker.rb index 5f276afe..d8e4fa2f 100755 --- a/app/workers/sync_extension_contents_at_versions_worker.rb +++ b/app/workers/sync_extension_contents_at_versions_worker.rb @@ -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)