b0VIM 8.1C _+joshJoshs-Mac-mini.local~josh/Projects/fastlane/fastlane/match/lib/match/importer.rbutf-8 3210#"! UtpUHVadUl?+* @ l k [ !  P  J  n ?  ` 9 nK P,9_B8$2~ should_skip_certificate_matching = params[:skip_certificate_matching] output_dir_profiles = File.join(storage.prefixed_working_directory, "profiles", prov_type.to_s) output_dir_certs = File.join(storage.prefixed_working_directory, "certs", cert_type.to_s) prov_type = Match.profile_type_sym(params[:type]) end UI.user_error!("Cert type '#{cert_type}' is not supported") else ].join(',') Spaceship::ConnectAPI::Certificate::CertificateType::MAC_INSTALLER_DISTRIBUTION certificate_type = [ when :mac_installer_distribution ].join(',') Spaceship::ConnectAPI::Certificate::CertificateType::DEVELOPER_ID_APPLICATION certificate_type = [ when :developer_id_application ].join(',') Spaceship::ConnectAPI::Certificate::CertificateType::DISTRIBUTION Spaceship::ConnectAPI::Certificate::CertificateType::MAC_APP_DISTRIBUTION, Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DISTRIBUTION, certificate_type = [ when :distribution, :enterprise ].join(',') Spaceship::ConnectAPI::Certificate::CertificateType::DEVELOPMENT Spaceship::ConnectAPI::Certificate::CertificateType::MAC_APP_DEVELOPMENT, Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DEVELOPMENT, certificate_type = [ when :development case cert_type cert_type = Match.cert_type_sym(params[:type]) # Map match type into Spaceship::ConnectAPI::Certificate::CertificateType UI.success("Repo is at: '#{storage.working_directory}'") encryption.decrypt_files if encryption }) working_directory: storage.working_directory git_url: params[:git_url], encryption = Encryption.for_storage_mode(params[:storage_mode], { # Encryption storage.download }) api_key: params[:api_key] api_key_path: params[:api_key_path], team_name: params[:team_name], team_id: params[:team_id], username: params[:username], readonly: params[:readonly], s3_object_prefix: params[:s3_object_prefix], s3_secret_access_key: params[:s3_secret_access_key], s3_access_key: params[:s3_access_key], s3_region: params[:s3_region], s3_bucket: params[:s3_bucket], google_cloud_project_id: params[:google_cloud_project_id].to_s, google_cloud_keys_file: params[:google_cloud_keys_file].to_s, google_cloud_bucket_name: params[:google_cloud_bucket_name].to_s, platform: params[:platform].to_s, type: params[:type].to_s, clone_branch_directly: params[:clone_branch_directly], git_user_email: params[:git_user_email], git_full_name: params[:git_full_name], git_branch: params[:git_branch], skip_docs: params[:skip_docs], shallow_clone: params[:shallow_clone], git_url: params[:git_url], storage = Storage.for_mode(params[:storage_mode], { # Storage profile_path = ensure_valid_file_path(profile_path, "Provisioning profile", ".mobileprovision or .provisionprofile", optional: true) p12_path = ensure_valid_file_path(p12_path, "Private key", ".p12") cert_path = ensure_valid_file_path(cert_path, "Certificate", ".cer") # Get and verify cert, p12 and profiles path def import_cert(params, cert_path: nil, p12_path: nil, profile_path: nil) class Importermodule Matchrequire 'fileutils'require 'fastlane_core/provisioning_profile'require_relative 'generator'require_relative 'module'require_relative 'storage'require_relative 'encryption'require_relative 'spaceship_ensure'ad6Hi6k$ | k  < w v } - W) /qA xpoZYcSKJ0`H@:6eend end end return @api_token @api_token ||= Spaceship::ConnectAPI::Token.from_json_file(params[:api_key_path]) if params[:api_key_path] @api_token ||= Spaceship::ConnectAPI::Token.create(params[:api_key]) if params[:api_key] def api_token(params) end file_path UI.user_error!("#{file_description} does not exist at path: #{file_path}") unless !file_path.nil? || optional file_path = File.exist?(file_path) ? file_path : nil file_path = File.absolute_path(file_path) unless file_path == "" file_path ||= UI.input("#{file_description} (#{file_extension}) path#{optional_file_message}:") optional_file_message = optional ? " or leave empty to skip this file" : "" def ensure_valid_file_path(file_path, file_description, file_extension, optional: false) end storage.save_changes!(files_to_commit: files_to_commit) encryption.encrypt_files if encryption # Encrypt and commit end IO.copy_stream(profile_path, dest_profile_path) files_to_commit.push(dest_profile_path) dest_profile_path = File.join(output_dir_profiles, "#{profile_type_name}_#{bundle_id}#{profile_extension}") profile_type_name = Match::Generator.profile_type_name(prov_type) profile_extension = FastlaneCore::ProvisioningProfile.profile_extension(profile_path) bundle_id = FastlaneCore::ProvisioningProfile.bundle_id(profile_path) FileUtils.mkdir_p(output_dir_profiles) unless profile_path.nil? IO.copy_stream(p12_path, dest_p12_path) IO.copy_stream(cert_path, dest_cert_path) # Copy files files_to_commit = [dest_cert_path, dest_p12_path] end dest_p12_path = File.join(output_dir_certs, "#{matching_cert.id}.p12") dest_cert_path = File.join(output_dir_certs, "#{matching_cert.id}.cer") FileUtils.mkdir_p(output_dir_certs) # Make dir if doesn't exist UI.user_error!("This certificate cannot be imported - the certificate contents did not match with any available on the Developer Portal") if matching_cert.nil? end cert.certificate_content == cert_contents_base_64 matching_cert = certs.find do |cert| cert_contents_base_64 = Base64.strict_encode64(File.binread(cert_path)) # Base64 encode contents to find match from API to find a cert ID certs = Spaceship::ConnectAPI::Certificate.all(filter: { certificateType: certificate_type }) end Spaceship::ConnectAPI.login(params[:username], use_portal: true, use_tunes: false, portal_team_id: params[:team_id], team_name: params[:team_name]) UI.message("Login to App Store Connect (#{params[:username]})") else Spaceship::ConnectAPI.token = token UI.message("Creating authorization token for App Store Connect API") if token token = api_token(params) # Need to get the cert id by comparing base64 encoded cert content with certificate content from the API responses else dest_p12_path = File.join(output_dir_certs, "#{p12_name}.p12") dest_cert_path = File.join(output_dir_certs, "#{cert_name}.cer") FileUtils.mkdir_p(output_dir_certs) # Make dir if doesn't exist p12_name = File.basename(p12_path, ".*") cert_name = File.basename(cert_path, ".*") if should_skip_certificate_matching # In case there is no access to Apple Developer portal but we have the certificates, keys and profiles