Skip to content

Commit

Permalink
Enterprise api key support (#60)
Browse files Browse the repository at this point in the history
* Update go-xcode

* Add api_key_enterprise_account step input
  • Loading branch information
godrei authored Nov 21, 2024
1 parent c31496d commit 1df1e70
Show file tree
Hide file tree
Showing 33 changed files with 389 additions and 495 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ steps:
| `api_key_path` | Local path or remote URL to the private key (p8 file) for App Store Connect API. This overrides the Bitrise-managed API connection, only set this input if you want to control the API connection on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise. The input value can be a file path (eg. `$TMPDIR/private_key.p8`) or an HTTPS URL. This input only takes effect if the other two connection override inputs are set too (`api_key_id`, `api_key_issuer_id`). | | |
| `api_key_id` | Private key ID used for App Store Connect authentication. This overrides the Bitrise-managed API connection, only set this input if you want to control the API connection on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise. This input only takes effect if the other two connection override inputs are set too (`api_key_path`, `api_key_issuer_id`). | | |
| `api_key_issuer_id` | Private key issuer ID used for App Store Connect authentication. This overrides the Bitrise-managed API connection, only set this input if you want to control the API connection on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise. This input only takes effect if the other two connection override inputs are set too (`api_key_path`, `api_key_id`). | | |
| `api_key_enterprise_account` | Indicates if the account is an enterprise type. This overrides the Bitrise-managed API connection, only set this input if you know you have an enterprise account. | required | `no` |
| `verbose_log` | If this input is set, the Step will print additional logs for debugging. | required | `no` |
</details>

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bitrise-io/go-utils v1.0.12
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23
github.com/bitrise-io/go-xcode v1.1.1
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.48
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.50
howett.net/plist v1.0.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23 h1:Dfh4nyZPuEtilBisidejqxBrkx9
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23/go.mod h1:3XUplo0dOWc3DqT2XA2SeHToDSg7+j1y1HTHibT2H68=
github.com/bitrise-io/go-xcode v1.1.1 h1:Krfa8iYZZWdLBuH7AXbufFZwL+Pys7etqvd8+Ehdwt8=
github.com/bitrise-io/go-xcode v1.1.1/go.mod h1:9OwsvrhZ4A2JxHVoEY7CPcABAKA+OE7FQqFfBfvbFuY=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.48 h1:nsd41UsIGZrPy94tlFxoDCfH2I19A9buPOA/cLgucjA=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.48/go.mod h1:KpxSPrRLgY0fscSajOyO/5h7MhapsqnSJr17oXEaPsg=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.50 h1:vh3miMo4lZb5fz8D1Tca0AerRv2hO3gZS4R5nEeSXKg=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.50/go.mod h1:KpxSPrRLgY0fscSajOyO/5h7MhapsqnSJr17oXEaPsg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
35 changes: 19 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"github.com/bitrise-io/go-steputils/output"
"github.com/bitrise-io/go-steputils/v2/stepconf"
v1command "github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/fileutil"
v1log "github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-io/go-utils/retry"
"github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/env"
"github.com/bitrise-io/go-utils/v2/fileutil"
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/retryhttp"
"github.com/bitrise-io/go-xcode/devportalservice"
"github.com/bitrise-io/go-xcode/models"
"github.com/bitrise-io/go-xcode/profileutil"
"github.com/bitrise-io/go-xcode/utility"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/bitrise-io/go-xcode/v2/autocodesign/localcodesignasset"
"github.com/bitrise-io/go-xcode/v2/autocodesign/profiledownloader"
"github.com/bitrise-io/go-xcode/v2/codesign"
"github.com/bitrise-io/go-xcode/v2/devportalservice"
"github.com/bitrise-io/go-xcode/v2/xcarchive"
"github.com/bitrise-io/go-xcode/xcodebuild"
"howett.net/plist"
Expand Down Expand Up @@ -67,9 +67,10 @@ type Inputs struct {
ManageVersionAndBuildNumber bool `env:"manage_version_and_build_number"`
ExportOptionsPlistContent string `env:"export_options_plist_content"`
// App Store Connect connection override
APIKeyPath stepconf.Secret `env:"api_key_path"`
APIKeyID string `env:"api_key_id"`
APIKeyIssuerID string `env:"api_key_issuer_id"`
APIKeyPath stepconf.Secret `env:"api_key_path"`
APIKeyID string `env:"api_key_id"`
APIKeyIssuerID string `env:"api_key_issuer_id"`
APIKeyEnterpriseAccount bool `env:"api_key_enterprise_account,opt[yes,no]"`
// Debugging
VerboseLog bool `env:"verbose_log,opt[yes,no]"`
// Output export
Expand Down Expand Up @@ -110,6 +111,11 @@ type Step struct {
commandFactory command.Factory
inputParser stepconf.InputParser
logger log.Logger
fileManager fileutil.FileManager
}

func NewStep(commandFactory command.Factory, inputParser stepconf.InputParser, logger log.Logger, fileManager fileutil.FileManager) Step {
return Step{commandFactory: commandFactory, inputParser: inputParser, logger: logger, fileManager: fileManager}
}

func (s Step) ProcessInputs() (Config, error) {
Expand Down Expand Up @@ -212,17 +218,18 @@ func (s Step) createCodesignManager(inputs Inputs, xcodeMajorVersion int) (codes
archive := codesign.NewArchive(a)

var serviceConnection *devportalservice.AppleDeveloperConnection = nil
devPortalClientFactory := devportalclient.NewFactory(s.logger)
devPortalClientFactory := devportalclient.NewFactory(s.logger, s.fileManager)
if inputs.BuildURL != "" && inputs.BuildAPIToken != "" {
if serviceConnection, err = devPortalClientFactory.CreateBitriseConnection(inputs.BuildURL, string(inputs.BuildAPIToken)); err != nil {
return codesign.Manager{}, err
}
}

connectionInputs := codesign.ConnectionOverrideInputs{
APIKeyPath: inputs.APIKeyPath,
APIKeyID: inputs.APIKeyID,
APIKeyIssuerID: inputs.APIKeyIssuerID,
APIKeyPath: inputs.APIKeyPath,
APIKeyID: inputs.APIKeyID,
APIKeyIssuerID: inputs.APIKeyIssuerID,
APIKeyEnterpriseAccount: inputs.APIKeyEnterpriseAccount,
}

appleAuthCredentials, err := codesign.SelectConnectionCredentials(authType, serviceConnection, connectionInputs, s.logger)
Expand Down Expand Up @@ -344,7 +351,7 @@ func (s Step) Run(opts Config) (RunOut, error) {
s.logger.Printf("Export options content provided, using it:")
fmt.Println(opts.ExportOptionsPlistContent)

if err := fileutil.WriteStringToFile(exportOptionsPath, opts.ExportOptionsPlistContent); err != nil {
if err := s.fileManager.Write(exportOptionsPath, opts.ExportOptionsPlistContent, 0700); err != nil {
return RunOut{}, fmt.Errorf("failed to write export options to file, error: %s", err)
}
} else {
Expand All @@ -355,7 +362,7 @@ func (s Step) Run(opts Config) (RunOut, error) {

s.logger.Printf("\ngenerated export options content:\n%s", exportOptionsContent)

if err := fileutil.WriteStringToFile(exportOptionsPath, exportOptionsContent); err != nil {
if err := s.fileManager.Write(exportOptionsPath, exportOptionsContent, 0700); err != nil {
return RunOut{}, fmt.Errorf("failed to write export options to file, error: %s", err)
}

Expand Down Expand Up @@ -470,11 +477,7 @@ func (s Step) ExportOutput(opts ExportOpts) error {
func RunStep() error {
envRepository := env.NewRepository()

step := Step{
commandFactory: command.NewFactory(envRepository),
inputParser: stepconf.NewInputParser(envRepository),
logger: log.NewLogger(),
}
step := NewStep(command.NewFactory(envRepository), stepconf.NewInputParser(envRepository), log.NewLogger(), fileutil.NewFileManager())

config, err := step.ProcessInputs()
if err != nil {
Expand Down
16 changes: 13 additions & 3 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ inputs:
on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise.
The input value can be a file path (eg. `$TMPDIR/private_key.p8`) or an HTTPS URL.
This input only takes effect if the other two connection override inputs are set too (`api_key_id`, `api_key_issuer_id`).
is_required: false
- api_key_id:
opts:
Expand All @@ -264,7 +263,6 @@ inputs:
This overrides the Bitrise-managed API connection, only set this input if you want to control the API connection
on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise.
This input only takes effect if the other two connection override inputs are set too (`api_key_path`, `api_key_issuer_id`).
is_required: false
- api_key_issuer_id:
opts:
Expand All @@ -276,7 +274,19 @@ inputs:
This overrides the Bitrise-managed API connection, only set this input if you want to control the API connection
on a step-level. Most of the time it's easier to set up the connection on the App Settings page on Bitrise.
This input only takes effect if the other two connection override inputs are set too (`api_key_path`, `api_key_id`).
is_required: false
- api_key_enterprise_account: "no"
opts:
category: App Store Connect connection override
title: App Store Connect API enterprise account
summary: Indicates if the account is an enterprise type. This overrides the Bitrise-managed API connection.
description: |-
Indicates if the account is an enterprise type.
This overrides the Bitrise-managed API connection, only set this input if you know you have an enterprise account.
value_options:
- "yes"
- "no"
is_required: true

# Debugging

Expand Down
105 changes: 105 additions & 0 deletions vendor/github.com/bitrise-io/go-utils/v2/fileutil/fileutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1df1e70

Please sign in to comment.