Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fastlane-plugin-appcircle_testing_distribution.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Gem::Specification.new do |spec|

spec.files = Dir["lib/**/*"] + Dir["images/*.png"] + %w(README.md LICENSE)
spec.require_paths = ['lib']
spec.metadata['rubygems_mfa_required'] = 'false'
spec.metadata['rubygems_mfa_required'] = 'true'
spec.required_ruby_version = '>= 2.6'

# Don't add a dependency to fastlane or fastlane_re
# since this would cause a circular dependency

# spec.add_dependency 'your-dependency', '~> 1.0.0'
spec.add_dependency "rest-client"
spec.add_dependency("rest-client")
end
4 changes: 2 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Dotenv.load

lane :test do
appcircle_testing_distribution(
personalAPIToken: ENV["AC_ACCESS_TOKEN"],
personalAPIToken: ENV["AC_PERSONAL_API_TOKEN"],
appPath: ENV["AC_APP_PATH"],
profileName: ENV["AC_PROFILE_NAME"],
createProfileIfNotExists: ENV["CREATE_PROFILE_IF_NOT_EXISTS"],
createProfileIfNotExists: ENV["CREATE_PROFILE_IF_NOT_EXISTS"] == "true",
message: ENV["AC_MESSAGE"],
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Actions
class AppcircleTestingDistributionAction < Action
def self.run(params)
personalAPIToken = params[:personalAPIToken]
personalAccessKey = params[:personalAccessKey]
profileName = params[:profileName]
appPath = params[:appPath]
message = params[:message]
Expand All @@ -24,8 +25,10 @@ def self.run(params)
UI.user_error!("Invalid file extension: #{file_extension}. For Android, use .apk or .aab. For iOS, use .ipa or .zip(.xcarchive).")
end

if personalAPIToken.nil?
UI.user_error!("Personal API Token is required to authenticate connections to Appcircle services. Please provide a valid access token")
if personalAPIToken.nil? && personalAccessKey.nil?
UI.user_error!("Either Personal API Token or Personal Access Key is required to authenticate connections to Appcircle services. Please provide a valid access token or access key")
elsif !personalAPIToken.nil? && !personalAccessKey.nil?
UI.user_error!("Personal API Token and Personal Access Key cannot be used together. Please provide only one authentication method")
elsif profileName.nil?
UI.user_error!("Distribution profile name is required to distribute applications. Please provide a distribution profile name")
elsif appPath.nil?
Expand All @@ -35,15 +38,19 @@ def self.run(params)
end


authToken = self.ac_login(personalAPIToken)
authToken = self.ac_login(personalAPIToken, personalAccessKey)

profileId = TDUploadService.get_profile_id(authToken, profileName, createProfileIfNotExists)
self.ac_upload(authToken, appPath, profileId, message)
end

def self.ac_login(personalAPIToken)
def self.ac_login(personalAPIToken, personalAccessKey)
begin
user = TDAuthService.get_ac_token(pat: personalAPIToken)
if personalAccessKey
user = TDAuthService.get_ac_token_with_personal_access_key(personal_access_key: personalAccessKey)
else
user = TDAuthService.get_ac_token(pat: personalAPIToken)
end
UI.success("Login is successful.")
return user.accessToken
rescue => e
Expand Down Expand Up @@ -117,8 +124,14 @@ def self.available_options
[
FastlaneCore::ConfigItem.new(key: :personalAPIToken,
env_name: "AC_PERSONAL_API_TOKEN",
description: "Provide Personal API Token to authenticate connections to Appcircle services",
optional: false,
description: "Provide Personal API Token to authenticate connections to Appcircle services (alternative to personalAccessKey)",
optional: true,
type: String),

FastlaneCore::ConfigItem.new(key: :personalAccessKey,
env_name: "AC_PERSONAL_ACCESS_KEY",
description: "Provide Personal Access Key to authenticate connections to Appcircle services (alternative to personalAPIToken)",
optional: true,
type: String),

FastlaneCore::ConfigItem.new(key: :profileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ def self.get_ac_token(pat:)



# Check response
if response.is_a?(Net::HTTPSuccess)
response_data = JSON.parse(response.body)

user = UserResponse.new(
accessToken: response_data['access_token']
)

return user
else
raise "HTTP Request failed (#{response.code} #{response.message})"
end
end

def self.get_ac_token_with_personal_access_key(personal_access_key:)
endpoint_url = 'https://auth.appcircle.io/auth/v1/token'
uri = URI(endpoint_url)

# Create HTTP request
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/x-www-form-urlencoded'
request['Accept'] = 'application/json'

# Encode parameters
params = { 'personal-access-key' => personal_access_key }
request.body = URI.encode_www_form(params)

# Make the HTTP request
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end

# Check response
if response.is_a?(Net::HTTPSuccess)
response_data = JSON.parse(response.body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module AppcircleTestingDistribution
VERSION = "0.2.2"
VERSION = "0.4.1"
end
end