fastlane-plugin-appcircle_testing_distribution 0.5.1 → 0.6.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb +20 -12
- data/lib/fastlane/plugin/appcircle_testing_distribution/helper/TDAuthService.rb +74 -31
- data/lib/fastlane/plugin/appcircle_testing_distribution/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd906fbc369757b3bed1ffc098e264fac7f7e14a599c0f6fa3ab16a1ad418329
|
|
4
|
+
data.tar.gz: d9e112c7ecb327872c9fef5f05c9655a469d222811074730b0efd9fa4097a486
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3ebc6c360f7d95556df5617485dcd77cd3995f78e7c44dc573216a2a5e25034e28edcb95e98eaad0f5651642bc62c8fda2e66d8a8c9b454a3c656524a47cf81
|
|
7
|
+
data.tar.gz: d4c14e0e42c7705b8c0163c38f0df0e3dc617ebe6a12fb2f2697878f349b6297d0628986d5d65e13c791cf9f7919bf8bd6a5f789bf6bc6e39856c9d6af5d19f8
|
data/README.md
CHANGED
|
@@ -93,11 +93,10 @@ Provide **either** `personalAPIToken` **or** `personalAccessKey`, not both. If n
|
|
|
93
93
|
|
|
94
94
|
- `personalAPIToken` / `personalAccessKey`: Provide exactly one to authenticate with Appcircle services. Providing both, or neither, fails with a descriptive error.
|
|
95
95
|
|
|
96
|
-
> **Note:** `subOrganizationName` is currently supported only when authenticating with `personalAPIToken`. When used together with `personalAccessKey`, the sub-organization switch is skipped with a warning.
|
|
97
|
-
|
|
98
96
|
### Other parameters
|
|
99
97
|
|
|
100
|
-
- `subOrganizationName` (optional): Required when the Root Organization's `personalAPIToken` is used, and you want to create the profile under a sub-organization. In this case, provide the name of the sub-organization in this field. If you directly used the sub-organization's `personalAPIToken`, this parameter is not needed.
|
|
98
|
+
- `subOrganizationName` (optional): Required when the Root Organization's `personalAPIToken` or `personalAccessKey` is used, and you want to create the profile under a sub-organization. In this case, provide the exact name of the sub-organization (case-sensitive) in this field. If you directly used the sub-organization's `personalAPIToken` or `personalAccessKey`, this parameter is not needed. If the plugin cannot find the sub-organization, or the token cannot access it, the lane fails. The plugin does not fall back to the root organization.
|
|
99
|
+
The option also reads the `AC_SUB_ORGANIZATION_NAME` environment variable, which the other Appcircle Fastlane plugins share.
|
|
101
100
|
- `profileName`: Specifies the profile that will be used for uploading the app.
|
|
102
101
|
- `createProfileIfNotExists` (optional): Ensures that a testing distribution profile is automatically created if it does not already exist; if the profile name already exists, the app will be uploaded to that existing profile instead.
|
|
103
102
|
- `profileCreationSettings` (optional): If `createProfileIfNotExists` is `true` and a new profile being created, the profile will be configured with these settings.
|
|
@@ -114,6 +113,7 @@ If you run a self-hosted Appcircle installation, point the plugin to your own en
|
|
|
114
113
|
|
|
115
114
|
- `authEndpoint` (optional): Authentication endpoint URL. Defaults to `https://auth.appcircle.io`.
|
|
116
115
|
- `apiEndpoint` (optional): API endpoint URL. Defaults to `https://api.appcircle.io`.
|
|
116
|
+
- Set `authEndpoint` and `apiEndpoint` together. If you set only one of them, the lane stops before it sends a request, so a self-hosted token never goes to the Appcircle cloud.
|
|
117
117
|
|
|
118
118
|
```ruby
|
|
119
119
|
appcircle_testing_distribution(
|
|
@@ -34,8 +34,8 @@ module Fastlane
|
|
|
34
34
|
appPath = params[:appPath]
|
|
35
35
|
message = params[:message]
|
|
36
36
|
#
|
|
37
|
-
authEndpoint = params[:authEndpoint]
|
|
38
|
-
apiEndpoint = params[:apiEndpoint]
|
|
37
|
+
authEndpoint = TDAuthService.normalize_endpoint(params[:authEndpoint], TDAuthService::CLOUD_AUTH_ENDPOINT)
|
|
38
|
+
apiEndpoint = TDAuthService.normalize_endpoint(params[:apiEndpoint], TDAuthService::CLOUD_API_ENDPOINT)
|
|
39
39
|
|
|
40
40
|
profileAuthType = AUTH_TYPE_MAPPING[profileAuthType] # map input to API values
|
|
41
41
|
|
|
@@ -47,6 +47,7 @@ module Fastlane
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# Auth
|
|
50
|
+
self.ac_validate_endpoints(authEndpoint, apiEndpoint)
|
|
50
51
|
authToken = self.ac_login(personal_api_token: personalAPIToken,
|
|
51
52
|
personal_access_key: personalAccessKey,
|
|
52
53
|
sub_organization_name: subOrganizationName,
|
|
@@ -60,6 +61,12 @@ module Fastlane
|
|
|
60
61
|
self.ac_upload(authToken, appPath, profileId, profileName, message, apiEndpoint)
|
|
61
62
|
end
|
|
62
63
|
|
|
64
|
+
def self.ac_validate_endpoints(auth_endpoint, api_endpoint)
|
|
65
|
+
TDAuthService.validate_endpoints(auth_endpoint: auth_endpoint, api_endpoint: api_endpoint)
|
|
66
|
+
rescue StandardError => e
|
|
67
|
+
UI.user_error!(e.message)
|
|
68
|
+
end
|
|
69
|
+
|
|
63
70
|
def self.ac_login(personal_api_token:, personal_access_key:, sub_organization_name:, auth_endpoint:, api_endpoint:)
|
|
64
71
|
begin
|
|
65
72
|
token = ''
|
|
@@ -72,15 +79,16 @@ module Fastlane
|
|
|
72
79
|
UI.success("Login is successful.")
|
|
73
80
|
token = user.accessToken
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
name = sub_organization_name.to_s.strip
|
|
83
|
+
unless name.empty?
|
|
84
|
+
token = TDAuthService.switch_to_sub_organization(
|
|
85
|
+
root_token: token,
|
|
86
|
+
name: name,
|
|
87
|
+
pat: personal_api_token || personal_access_key,
|
|
88
|
+
auth_endpoint: auth_endpoint,
|
|
89
|
+
api_endpoint: api_endpoint
|
|
90
|
+
)
|
|
91
|
+
UI.message("Switched to sub-organization: #{name}")
|
|
84
92
|
end
|
|
85
93
|
|
|
86
94
|
return token
|
|
@@ -198,7 +206,7 @@ module Fastlane
|
|
|
198
206
|
|
|
199
207
|
FastlaneCore::ConfigItem.new(key: :subOrganizationName,
|
|
200
208
|
env_name: "AC_SUB_ORGANIZATION_NAME",
|
|
201
|
-
description: "Optional: Sub-organization name for app distribution.
|
|
209
|
+
description: "Optional: Sub-organization name for app distribution. Use it when the Personal API Token or Personal Access Key belongs to the root organization. Leave empty to use the organization of the token",
|
|
202
210
|
optional: true,
|
|
203
211
|
type: String),
|
|
204
212
|
|
|
@@ -13,6 +13,33 @@ class UserResponse
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
module TDAuthService
|
|
16
|
+
class TokenRequestError < RuntimeError
|
|
17
|
+
attr_reader :code
|
|
18
|
+
|
|
19
|
+
def initialize(code, message)
|
|
20
|
+
super(message)
|
|
21
|
+
@code = code
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
CLOUD_AUTH_ENDPOINT = 'https://auth.appcircle.io'.freeze
|
|
26
|
+
CLOUD_API_ENDPOINT = 'https://api.appcircle.io'.freeze
|
|
27
|
+
|
|
28
|
+
def self.validate_endpoints(auth_endpoint:, api_endpoint:)
|
|
29
|
+
return if cloud_endpoint?(auth_endpoint, CLOUD_AUTH_ENDPOINT) == cloud_endpoint?(api_endpoint, CLOUD_API_ENDPOINT)
|
|
30
|
+
|
|
31
|
+
raise 'Set both authEndpoint and apiEndpoint for a self-hosted Appcircle server, or leave both empty for the Appcircle cloud.'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.normalize_endpoint(endpoint, cloud_endpoint)
|
|
35
|
+
value = endpoint.to_s.strip.sub(%r{/+\z}, '')
|
|
36
|
+
value.empty? ? cloud_endpoint : value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.cloud_endpoint?(endpoint, cloud_endpoint)
|
|
40
|
+
normalize_endpoint(endpoint, cloud_endpoint).casecmp?(cloud_endpoint)
|
|
41
|
+
end
|
|
42
|
+
|
|
16
43
|
def self.get_ac_token(pat:, sub_organization_id: nil, auth_endpoint: 'https://auth.appcircle.io')
|
|
17
44
|
endpoint_url = "#{auth_endpoint}/auth/v2/token"
|
|
18
45
|
uri = URI(endpoint_url)
|
|
@@ -42,35 +69,7 @@ module TDAuthService
|
|
|
42
69
|
|
|
43
70
|
return user
|
|
44
71
|
else
|
|
45
|
-
raise "Error: (#{response.code} #{response.message})."
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def self.get_organization_id(access_token:, name:, api_endpoint: 'https://api.appcircle.io')
|
|
50
|
-
endpoint_url = "#{api_endpoint}/identity/v1/organizations"
|
|
51
|
-
uri = URI(endpoint_url)
|
|
52
|
-
|
|
53
|
-
# Create HTTP request
|
|
54
|
-
request = Net::HTTP::Get.new(uri)
|
|
55
|
-
request['Authorization'] = "Bearer #{access_token}"
|
|
56
|
-
request['Accept'] = 'application/json'
|
|
57
|
-
|
|
58
|
-
# Make the HTTP request
|
|
59
|
-
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
60
|
-
http.request(request)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Check response
|
|
64
|
-
if response.is_a?(Net::HTTPSuccess)
|
|
65
|
-
response_data = JSON.parse(response.body)
|
|
66
|
-
organizations = response_data['data']
|
|
67
|
-
organization = organizations.find { |org| org['name'] == name }
|
|
68
|
-
|
|
69
|
-
raise "Organization with name '#{name}' not found" unless organization
|
|
70
|
-
return organization['id']
|
|
71
|
-
|
|
72
|
-
else
|
|
73
|
-
raise "Error: (#{response.code} #{response.message})"
|
|
72
|
+
raise TokenRequestError.new(response.code, "Error: (#{response.code} #{response.message}).")
|
|
74
73
|
end
|
|
75
74
|
end
|
|
76
75
|
|
|
@@ -84,7 +83,7 @@ module TDAuthService
|
|
|
84
83
|
request['Accept'] = 'application/json'
|
|
85
84
|
|
|
86
85
|
# Encode parameters
|
|
87
|
-
params = {
|
|
86
|
+
params = { pat: personal_access_key }
|
|
88
87
|
request.body = URI.encode_www_form(params)
|
|
89
88
|
|
|
90
89
|
# Make the HTTP request
|
|
@@ -105,4 +104,48 @@ module TDAuthService
|
|
|
105
104
|
raise "Error: (#{response.code} #{response.message})."
|
|
106
105
|
end
|
|
107
106
|
end
|
|
108
|
-
|
|
107
|
+
|
|
108
|
+
def self.get_organization_id(access_token:, name:, api_endpoint: 'https://api.appcircle.io')
|
|
109
|
+
uri = URI("#{api_endpoint}/identity/v1/organizations")
|
|
110
|
+
uri.query = URI.encode_www_form(page: 1, perPage: 1000)
|
|
111
|
+
|
|
112
|
+
request = Net::HTTP::Get.new(uri)
|
|
113
|
+
request['Authorization'] = "Bearer #{access_token}"
|
|
114
|
+
request['Accept'] = 'application/json'
|
|
115
|
+
|
|
116
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
117
|
+
http.request(request)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
raise "Could not list the organizations of this token (HTTP #{response.code})." unless response.kind_of?(Net::HTTPSuccess)
|
|
121
|
+
|
|
122
|
+
payload = begin
|
|
123
|
+
JSON.parse(response.body)
|
|
124
|
+
rescue JSON::ParserError
|
|
125
|
+
nil
|
|
126
|
+
end
|
|
127
|
+
raise 'Could not list the organizations of this token (unexpected response).' unless payload.kind_of?(Hash)
|
|
128
|
+
|
|
129
|
+
organizations = payload['data'].kind_of?(Array) ? payload['data'] : []
|
|
130
|
+
organization = organizations.find { |org| org['name'] == name }
|
|
131
|
+
raise "Sub-organization '#{name}' could not be found or is not accessible with this token." if organization.nil? || organization['id'].to_s.empty?
|
|
132
|
+
|
|
133
|
+
organization['id']
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def self.switch_to_sub_organization(root_token:, name:, pat:, auth_endpoint:, api_endpoint:)
|
|
137
|
+
organization_id = get_organization_id(access_token: root_token, name: name, api_endpoint: api_endpoint)
|
|
138
|
+
begin
|
|
139
|
+
user = get_ac_token(pat: pat, sub_organization_id: organization_id, auth_endpoint: auth_endpoint)
|
|
140
|
+
rescue TokenRequestError => e
|
|
141
|
+
raise "Could not authenticate against sub-organization '#{name}' (HTTP #{e.code})."
|
|
142
|
+
rescue JSON::ParserError
|
|
143
|
+
raise "Could not obtain an access token for sub-organization '#{name}'."
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
token = user.accessToken
|
|
147
|
+
raise "Could not obtain an access token for sub-organization '#{name}'." if token.nil? || token.to_s.empty?
|
|
148
|
+
|
|
149
|
+
token
|
|
150
|
+
end
|
|
151
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fastlane-plugin-appcircle_testing_distribution
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0.beta.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- appcircleio
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|
|
@@ -55,9 +55,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
55
55
|
version: '2.6'
|
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
|
-
- - "
|
|
58
|
+
- - ">"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version:
|
|
60
|
+
version: 1.3.1
|
|
61
61
|
requirements: []
|
|
62
62
|
rubygems_version: 3.3.27
|
|
63
63
|
signing_key:
|