fastlane-plugin-appcircle_publish 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a2447b7731283aab85a8ea047d689155b592d4ef845b3c52071164998cb6f33
4
- data.tar.gz: 759aebf69adb72b317cf4b136c23c622f9a4e5874d4dd1173d74b732b3f2b136
3
+ metadata.gz: 1c4e94b6f8cc58b106ce8652c09c3c77ea1c14c1fd950bd81e9f2f8f36754d92
4
+ data.tar.gz: 2c902803a48cfdf8f0b9f087661896b4afec1ac789ace0e58c0e6de93bdefe74
5
5
  SHA512:
6
- metadata.gz: 5fa16f53e027d9263f311261c68d8c8749d82d284756dbf04226b05fe67081804e5452267ef4267c538703cbfb4af016f1178b18226e742b7636b27ce3e96c99
7
- data.tar.gz: 97fc6d88f019678d5b4f3cda118305600a012eefea3f29a32a75a885320efff17f7c1281dce2c746bab79f9859ef199ebe8238995839e0d6b95ce827ed9ff251
6
+ metadata.gz: 6783ae233b7f852373432cbbb0ffa06c640b302a32d62b2fc3b7a0786e452aa46d4443e7e6f2af1e40ae7dd80c2a9b457fa030d4967019565e451ce177363fd3
7
+ data.tar.gz: 80a535b66ade4e8272b588003b6e0e48ddf137a3f73b50bad1b8bb1888e98a66350f72bf53547bbfa1f7a8f03a66f6f781412ad808c82adc202b67c4788a3f98
data/README.md CHANGED
@@ -32,9 +32,9 @@ Note: Both **Appcircle Cloud** and **self-hosted** Appcircle installations are s
32
32
 
33
33
  To generate a Personal API Token:
34
34
 
35
- 1. Open the **My Organization** screen from your profile avatar at the bottom left.
36
- 2. Go to the **Security** section and find the **Personal Access Key** card.
37
- 3. Press **Generate Key** to generate your token.
35
+ 1. In the left sidebar, go to **Organization** > **Security**.
36
+ 2. Find the **Personal access key** section.
37
+ 3. Select **Generate key** to generate your token.
38
38
 
39
39
  ![Token Generation](https://raw.githubusercontent.com/appcircleio/fastlane-plugin-appcircle_publish/main/images/PAT.png)
40
40
 
@@ -111,6 +111,7 @@ fastlane add_plugin appcircle_publish
111
111
  ```
112
112
 
113
113
  - `personalAPIToken` / `personalAccessKey`: Provide exactly one to authenticate with Appcircle services. Providing both, or neither, fails with a descriptive error.
114
+ - `subOrganizationName` (optional): Sub-organization name of the target Publish profile. See [Sub-Organizations](#sub-organizations).
114
115
  - `platform`: Target platform of the Publish profile: `ios` or `android`.
115
116
  - `publishProfile`: Name of the Publish profile to target.
116
117
  - `upload` (default `false`): Upload `appPath` as a new app version.
@@ -123,6 +124,7 @@ If you run a self-hosted Appcircle installation, point the action to your own en
123
124
 
124
125
  - `authEndpoint` (optional): Authentication endpoint URL. Defaults to `https://auth.appcircle.io`.
125
126
  - `apiEndpoint` (optional): API endpoint URL. Defaults to `https://api.appcircle.io`.
127
+ - 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.
126
128
 
127
129
  ```ruby
128
130
  appcircle_publish(
@@ -137,6 +139,26 @@ If you run a self-hosted Appcircle installation, point the action to your own en
137
139
 
138
140
  > **Self-signed or private CA certificates:** If your self-hosted Appcircle server uses a self-signed certificate (or one issued by a private/internal CA), requests will fail certificate validation. The plugin does not disable TLS verification. Trust the server's CA on the machine running Fastlane: add it to the system certificate store, or point the `SSL_CERT_FILE` environment variable at a PEM bundle that includes it.
139
141
 
142
+ ### Sub-Organizations
143
+
144
+ If your Personal API Token or Personal Access Key belongs to the root organization and the target Publish profile is in a sub-organization, set the optional `subOrganizationName` parameter. The action then uses a token of that sub-organization for all later requests. If you use a token or key of the sub-organization, you do not need this parameter.
145
+
146
+ - `subOrganizationName` (optional): The exact name of the sub-organization (case-sensitive). If the action cannot find the sub-organization, or the token cannot access it, the lane fails. The action does not fall back to the root organization.
147
+
148
+ The option also reads the `AC_SUB_ORGANIZATION_NAME` environment variable. The other Appcircle Fastlane plugins use the same variable, so if your lane sets it for one action, it applies to this action too.
149
+
150
+ ```ruby
151
+ appcircle_publish(
152
+ personalAPIToken: "$(AC_PERSONAL_API_TOKEN)",
153
+ subOrganizationName: "My Sub Organization",
154
+ platform: "$(AC_PLATFORM)",
155
+ publishProfile: "$(AC_PUBLISH_PROFILE)",
156
+ upload: true,
157
+ publish: true,
158
+ appPath: "$(AC_APP_PATH)"
159
+ )
160
+ ```
161
+
140
162
  ### Leveraging Environment Variables
141
163
 
142
164
  Utilize environment variables seamlessly by substituting the parameters with $(VARIABLE_NAME) in your task inputs. The plugin automatically retrieves values from the specified environment variables within your pipeline.
@@ -28,8 +28,9 @@ module Fastlane
28
28
  def self.run(params)
29
29
  personalAPIToken = params[:personalAPIToken]
30
30
  personalAccessKey = params[:personalAccessKey]
31
- @@authEndpoint = params[:authEndpoint]
32
- @@apiEndpoint = params[:apiEndpoint]
31
+ subOrganizationName = params[:subOrganizationName]
32
+ @@authEndpoint = AuthService.normalize_endpoint(params[:authEndpoint], AuthService::CLOUD_AUTH_ENDPOINT)
33
+ @@apiEndpoint = AuthService.normalize_endpoint(params[:apiEndpoint], AuthService::CLOUD_API_ENDPOINT)
33
34
  platform = params[:platform] && params[:platform].downcase
34
35
  publishProfile = params[:publishProfile]
35
36
  appPath = params[:appPath]
@@ -65,11 +66,13 @@ module Fastlane
65
66
  end
66
67
 
67
68
  # --- Auth + profile ---
69
+ self.ac_validate_endpoints(@@authEndpoint, @@apiEndpoint)
68
70
  if personalAPIToken.nil?
69
71
  self.ac_login_with_pak(personalAccessKey)
70
72
  else
71
73
  self.ac_login_with_pat(personalAPIToken)
72
74
  end
75
+ self.ac_switch_sub_organization(subOrganizationName, personalAPIToken, personalAccessKey)
73
76
 
74
77
  profileId = PublishUploadService.get_publish_profile_id(auth_token: @@apiToken, platform: platform, profile_name: publishProfile, api_endpoint: @@apiEndpoint)
75
78
 
@@ -126,6 +129,28 @@ module Fastlane
126
129
  raise e
127
130
  end
128
131
 
132
+ def self.ac_validate_endpoints(auth_endpoint, api_endpoint)
133
+ AuthService.validate_endpoints(auth_endpoint: auth_endpoint, api_endpoint: api_endpoint)
134
+ rescue StandardError => e
135
+ UI.user_error!(e.message)
136
+ end
137
+
138
+ def self.ac_switch_sub_organization(sub_organization_name, personal_api_token, personal_access_key)
139
+ name = sub_organization_name.to_s.strip
140
+ return if name.empty?
141
+
142
+ @@apiToken = AuthService.switch_to_sub_organization(
143
+ root_token: @@apiToken,
144
+ name: name,
145
+ pat: personal_api_token || personal_access_key,
146
+ auth_endpoint: @@authEndpoint,
147
+ api_endpoint: @@apiEndpoint
148
+ )
149
+ UI.message("Switched to sub-organization: #{name}")
150
+ rescue StandardError => e
151
+ UI.user_error!(e.message)
152
+ end
153
+
129
154
  def self.checkTaskStatus(taskId)
130
155
  uri = URI.parse("#{@@apiEndpoint}/task/v1/tasks/#{taskId}")
131
156
 
@@ -232,6 +257,12 @@ module Fastlane
232
257
  optional: true,
233
258
  type: String),
234
259
 
260
+ FastlaneCore::ConfigItem.new(key: :subOrganizationName,
261
+ env_name: "AC_SUB_ORGANIZATION_NAME",
262
+ description: "Optional: Sub-organization name of the target publish profile. 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",
263
+ optional: true,
264
+ type: String),
265
+
235
266
  FastlaneCore::ConfigItem.new(key: :authEndpoint,
236
267
  env_name: "AC_AUTH_ENDPOINT",
237
268
  description: "Optional: Authentication endpoint URL for self-hosted Appcircle installations. Defaults to the Appcircle cloud",
@@ -12,7 +12,34 @@ class UserResponse
12
12
  end
13
13
 
14
14
  module AuthService
15
- def self.get_ac_token(pat:, auth_endpoint: 'https://auth.appcircle.io')
15
+ class TokenRequestError < RuntimeError
16
+ attr_reader :code
17
+
18
+ def initialize(code, message)
19
+ super(message)
20
+ @code = code
21
+ end
22
+ end
23
+
24
+ CLOUD_AUTH_ENDPOINT = 'https://auth.appcircle.io'.freeze
25
+ CLOUD_API_ENDPOINT = 'https://api.appcircle.io'.freeze
26
+
27
+ def self.validate_endpoints(auth_endpoint:, api_endpoint:)
28
+ return if cloud_endpoint?(auth_endpoint, CLOUD_AUTH_ENDPOINT) == cloud_endpoint?(api_endpoint, CLOUD_API_ENDPOINT)
29
+
30
+ raise 'Set both authEndpoint and apiEndpoint for a self-hosted Appcircle server, or leave both empty for the Appcircle cloud.'
31
+ end
32
+
33
+ def self.normalize_endpoint(endpoint, cloud_endpoint)
34
+ value = endpoint.to_s.strip.sub(%r{/+\z}, '')
35
+ value.empty? ? cloud_endpoint : value
36
+ end
37
+
38
+ def self.cloud_endpoint?(endpoint, cloud_endpoint)
39
+ normalize_endpoint(endpoint, cloud_endpoint).casecmp?(cloud_endpoint)
40
+ end
41
+
42
+ def self.get_ac_token(pat:, sub_organization_id: nil, auth_endpoint: 'https://auth.appcircle.io')
16
43
  endpoint_url = "#{auth_endpoint}/auth/v2/token"
17
44
  uri = URI(endpoint_url)
18
45
 
@@ -23,6 +50,7 @@ module AuthService
23
50
 
24
51
  # Encode parameters
25
52
  params = { pat: pat }
53
+ params[:subOrganizationId] = sub_organization_id if sub_organization_id
26
54
  request.body = URI.encode_www_form(params)
27
55
 
28
56
  # Make the HTTP request
@@ -40,7 +68,7 @@ module AuthService
40
68
 
41
69
  return user
42
70
  else
43
- raise "HTTP Request failed (#{response.code} #{response.message})"
71
+ raise TokenRequestError.new(response.code, "HTTP Request failed (#{response.code} #{response.message})")
44
72
  end
45
73
  end
46
74
 
@@ -54,7 +82,7 @@ module AuthService
54
82
  request['Accept'] = 'application/json'
55
83
 
56
84
  # Encode parameters
57
- params = { 'personal-access-key' => personal_access_key }
85
+ params = { pat: personal_access_key }
58
86
  request.body = URI.encode_www_form(params)
59
87
 
60
88
  # Make the HTTP request
@@ -75,4 +103,48 @@ module AuthService
75
103
  raise "HTTP Request failed (#{response.code} #{response.message})"
76
104
  end
77
105
  end
106
+
107
+ def self.get_organization_id(access_token:, name:, api_endpoint: 'https://api.appcircle.io')
108
+ uri = URI("#{api_endpoint}/identity/v1/organizations")
109
+ uri.query = URI.encode_www_form(page: 1, perPage: 1000)
110
+
111
+ request = Net::HTTP::Get.new(uri)
112
+ request['Authorization'] = "Bearer #{access_token}"
113
+ request['Accept'] = 'application/json'
114
+
115
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
116
+ http.request(request)
117
+ end
118
+
119
+ raise "Could not list the organizations of this token (HTTP #{response.code})." unless response.kind_of?(Net::HTTPSuccess)
120
+
121
+ payload = begin
122
+ JSON.parse(response.body)
123
+ rescue JSON::ParserError
124
+ nil
125
+ end
126
+ raise 'Could not list the organizations of this token (unexpected response).' unless payload.kind_of?(Hash)
127
+
128
+ organizations = payload['data'].kind_of?(Array) ? payload['data'] : []
129
+ organization = organizations.find { |org| org['name'] == name }
130
+ raise "Sub-organization '#{name}' could not be found or is not accessible with this token." if organization.nil? || organization['id'].to_s.empty?
131
+
132
+ organization['id']
133
+ end
134
+
135
+ def self.switch_to_sub_organization(root_token:, name:, pat:, auth_endpoint:, api_endpoint:)
136
+ organization_id = get_organization_id(access_token: root_token, name: name, api_endpoint: api_endpoint)
137
+ begin
138
+ user = get_ac_token(pat: pat, sub_organization_id: organization_id, auth_endpoint: auth_endpoint)
139
+ rescue TokenRequestError => e
140
+ raise "Could not authenticate against sub-organization '#{name}' (HTTP #{e.code})."
141
+ rescue JSON::ParserError
142
+ raise "Could not obtain an access token for sub-organization '#{name}'."
143
+ end
144
+
145
+ token = user.accessToken
146
+ raise "Could not obtain an access token for sub-organization '#{name}'." if token.nil? || token.to_s.empty?
147
+
148
+ token
149
+ end
78
150
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module AppcirclePublish
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0.beta.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-appcircle_publish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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-07-28 00:00:00.000000000 Z
11
+ date: 2026-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -54,9 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  version: '2.6'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ">="
57
+ - - ">"
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: 1.3.1
60
60
  requirements: []
61
61
  rubygems_version: 3.3.27
62
62
  signing_key: