Skip to content

Commit d1ee585

Browse files
author
Kamil Piotrowski
committed
Add API_KEY to authenticate notarization request
1 parent 16606cb commit d1ee585

File tree

7 files changed

+84
-24
lines changed

7 files changed

+84
-24
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ Supported configurations:
208208
variable. If this value isn't set, we'll attempt to use the `AC_PASSWORD`
209209
environment variable as a default.
210210

211+
* `api_key` (`string` _optional_) - The API key required for JWT authentication while using validation, upload, and notarization. This option will search the following directories in sequence for a private key file with the name of 'AuthKey_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys' and '~/.appstoreconnect/private_keys'. API key can be used instead of providing username and password.
212+
213+
* `api_issuer` (`string` _optional_ ) - The Issuer ID. Required if --api_key is specified.
214+
211215
* `provider` (`string` _optional_) - The App Store Connect provider when using
212216
multiple teams within App Store Connect. If this isn't set, we'll attempt
213217
to read the `AC_PROVIDER` environment variable as a default.

cmd/gon/item.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func (i *item) notarize(ctx context.Context, opts *processOptions) error {
7171
BundleId: bundleId,
7272
Username: opts.Config.AppleId.Username,
7373
Password: opts.Config.AppleId.Password,
74+
APIKey: opts.Config.AppleId.APIKey,
75+
APIIssuer: opts.Config.AppleId.APIIssuer,
7476
Provider: opts.Config.AppleId.Provider,
7577
Logger: opts.Logger.Named("notarize"),
7678
Status: &statusHuman{Prefix: opts.Prefix, Lock: lock},

cmd/gon/main.go

+32-20
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,43 @@ func realMain() int {
145145
if cfg.AppleId == nil {
146146
cfg.AppleId = &config.AppleId{}
147147
}
148-
if cfg.AppleId.Username == "" {
149-
appleIdUsername, ok := os.LookupEnv("AC_USERNAME")
150-
if !ok {
151-
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No apple_id username provided\n")
152-
color.New(color.FgRed).Fprintf(os.Stdout,
153-
"An Apple ID username must be specified in the `apple_id` block or\n"+
154-
"it must exist in the environment as AC_USERNAME,\n"+
155-
"otherwise we won't be able to authenticate with Apple to notarize.\n")
148+
149+
if len(cfg.AppleId.APIKey) > 0 || len(cfg.AppleId.APIIssuer) > 0 {
150+
if cfg.AppleId.APIKey == "" {
151+
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No api_key provided, but used api_issuer\n")
156152
return 1
157153
}
158-
159-
cfg.AppleId.Username = appleIdUsername
160-
}
161-
162-
if cfg.AppleId.Password == "" {
163-
if _, ok := os.LookupEnv("AC_PASSWORD"); !ok {
164-
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No apple_id password provided\n")
165-
color.New(color.FgRed).Fprintf(os.Stdout,
166-
"An Apple ID password (or lookup directive) must be specified in the\n"+
167-
"`apple_id` block or it must exist in the environment as AC_PASSWORD,\n"+
168-
"otherwise we won't be able to authenticate with Apple to notarize.\n")
154+
if cfg.AppleId.APIIssuer == "" {
155+
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No api_issuer provided\n")
169156
return 1
170157
}
158+
} else {
159+
if cfg.AppleId.Username == "" {
160+
appleIdUsername, ok := os.LookupEnv("AC_USERNAME")
161+
if !ok {
162+
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No apple_id username provided\n")
163+
color.New(color.FgRed).Fprintf(os.Stdout,
164+
"An Apple ID username must be specified in the `apple_id` block or\n"+
165+
"it must exist in the environment as AC_USERNAME,\n"+
166+
"otherwise we won't be able to authenticate with Apple to notarize.\n")
167+
return 1
168+
}
169+
170+
cfg.AppleId.Username = appleIdUsername
171+
}
171172

172-
cfg.AppleId.Password = "@env:AC_PASSWORD"
173+
if cfg.AppleId.Password == "" {
174+
if _, ok := os.LookupEnv("AC_PASSWORD"); !ok {
175+
color.New(color.Bold, color.FgRed).Fprintf(os.Stdout, "❗️ No apple_id password provided\n")
176+
color.New(color.FgRed).Fprintf(os.Stdout,
177+
"An Apple ID password (or lookup directive) must be specified in the\n"+
178+
"`apple_id` block or it must exist in the environment as AC_PASSWORD,\n"+
179+
"otherwise we won't be able to authenticate with Apple to notarize.\n")
180+
return 1
181+
}
182+
183+
cfg.AppleId.Password = "@env:AC_PASSWORD"
184+
}
173185
}
174186
if cfg.AppleId.Provider == "" {
175187
cfg.AppleId.Provider = os.Getenv("AC_PROVIDER")

internal/config/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ type AppleId struct {
4747
// specified if you're using an Apple ID account that has multiple
4848
// teams.
4949
Provider string `hcl:"provider,optional"`
50+
51+
// APIKey is required for JWT authentication while using validation, upload, and notarization.
52+
// This option will search the following directories in sequence for a private key file
53+
// with the name of 'AuthKey_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys',
54+
// and '~/.appstoreconnect/private_keys'.
55+
APIKey string `hcl:"api_key,optional"`
56+
57+
//APIIssuer is Issuer ID. Required if --apiKey is specified.
58+
APIIssuer string `hcl:"api_issuer,optional"`
5059
}
5160

5261
// Notarize are the options for notarizing a pre-built file.

notarize/info.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ func info(ctx context.Context, uuid string, opts *Options) (*Info, error) {
8181
"altool",
8282
"--notarization-info",
8383
uuid,
84-
"-u", opts.Username,
85-
"-p", opts.Password,
8684
"--output-format", "xml",
8785
}
8886

87+
if len(opts.Username) > 0 {
88+
cmd.Args = append(cmd.Args,
89+
"-u", opts.Username,
90+
"-p", opts.Password,
91+
)
92+
}
93+
94+
if len(opts.APIKey) > 0 {
95+
cmd.Args = append(cmd.Args,
96+
"--apiKey", opts.APIKey,
97+
"--apiIssuer", opts.APIIssuer,
98+
)
99+
}
100+
89101
// We store all output in out for logging and in case there is an error
90102
var out, combined bytes.Buffer
91103
cmd.Stdout = io.MultiWriter(&out, &combined)

notarize/notarize.go

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ type Options struct {
2727
// read from the keychain and environment variables, respectively.
2828
Password string
2929

30+
// APIKey is required for JWT authentication while using validation, upload, and notarization.
31+
// This option will search the following directories in sequence for a private key file
32+
// with the name of 'AuthKey_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys',
33+
// and '~/.appstoreconnect/private_keys'.
34+
APIKey string
35+
36+
//APIIssuer is Issuer ID. Required if --apiKey is specified.
37+
APIIssuer string
38+
3039
// Provider is the Apple Connect provider to use. This is optional
3140
// and is only used for Apple Connect accounts that support multiple
3241
// providers.

notarize/upload.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ func upload(ctx context.Context, opts *Options) (string, error) {
4141
"altool",
4242
"--notarize-app",
4343
"--primary-bundle-id", opts.BundleId,
44-
"-u", opts.Username,
45-
"-p", opts.Password,
44+
}
45+
46+
if len(opts.Username) > 0 {
47+
cmd.Args = append(cmd.Args,
48+
"-u", opts.Username,
49+
"-p", opts.Password,
50+
)
51+
}
52+
53+
if len(opts.APIKey) > 0 {
54+
cmd.Args = append(cmd.Args,
55+
"--apiKey", opts.APIKey,
56+
"--apiIssuer", opts.APIIssuer,
57+
)
4658
}
4759

4860
if opts.Provider != "" {

0 commit comments

Comments
 (0)