Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit b23c789

Browse files
authored
Merge pull request #72 from LuisUrr/notarytool_support
feat: Move to Notarytool
2 parents c3afcf0 + ee5bbfd commit b23c789

18 files changed

+346
-447
lines changed

.gon.hcl

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bundle_id = "com.mitchellh.gon"
44
apple_id {
55
username = "[email protected]"
66
password = "@env:AC_PASSWORD"
7+
provider = "UL304B4VGY"
78
}
89

910
sign {

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bundle_id = "com.mitchellh.example.terraform"
149149
apple_id {
150150
username = "[email protected]"
151151
password = "@env:AC_PASSWORD"
152+
provider = "UL304B4VGY"
152153
}
153154
154155
sign {
@@ -171,7 +172,8 @@ zip {
171172
"bundle_id" : "com.mitchellh.example.terraform",
172173
"apple_id": {
173174
"username" : "[email protected]",
174-
"password": "@env:AC_PASSWORD"
175+
"password": "@env:AC_PASSWORD",
176+
"provider": "UL304B4VGY"
175177
},
176178
"sign" :{
177179
"application_identity" : "Developer ID Application: Mitchell Hashimoto"
@@ -216,7 +218,7 @@ Supported configurations:
216218
**NOTE**: If you have 2FA enabled, the password must be an application password, not
217219
your normal apple id password. See [Troubleshooting](#troubleshooting) for details.
218220

219-
* `provider` (`string` _optional_) - The App Store Connect provider when using
221+
* `provider` (`string`) - The App Store Connect provider when using
220222
multiple teams within App Store Connect. If this isn't set, we'll attempt
221223
to read the `AC_PROVIDER` environment variable as a default.
222224

cmd/gon/item.go

+9-79
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package main
22

33
import (
44
"context"
5-
"fmt"
65
"os"
76
"sync"
87

98
"github.com/fatih/color"
109
"github.com/hashicorp/go-hclog"
11-
"github.com/hashicorp/go-multierror"
1210

1311
"github.com/mitchellh/gon/internal/config"
1412
"github.com/mitchellh/gon/notarize"
@@ -66,19 +64,18 @@ func (i *item) notarize(ctx context.Context, opts *processOptions) error {
6664
}
6765

6866
// Start notarization
69-
info, err := notarize.Notarize(ctx, &notarize.Options{
70-
File: i.Path,
71-
BundleId: bundleId,
72-
Username: opts.Config.AppleId.Username,
73-
Password: opts.Config.AppleId.Password,
74-
Provider: opts.Config.AppleId.Provider,
75-
Logger: opts.Logger.Named("notarize"),
76-
Status: &statusHuman{Prefix: opts.Prefix, Lock: lock},
77-
UploadLock: opts.UploadLock,
67+
_, _, err := notarize.Notarize(ctx, &notarize.Options{
68+
File: i.Path,
69+
DeveloperId: opts.Config.AppleId.Username,
70+
Password: opts.Config.AppleId.Password,
71+
Provider: opts.Config.AppleId.Provider,
72+
Logger: opts.Logger.Named("notarize"),
73+
Status: &statusHuman{Prefix: opts.Prefix, Lock: lock},
74+
UploadLock: opts.UploadLock,
7875
})
7976

8077
// Save the error state. We don't save the notarization result yet
81-
// because we don't know it for sure until we download the log file.
78+
// because we don't know it for sure until we retrieve the log information.
8279
i.State.NotarizeError = err
8380

8481
// If we had an error, we mention immediate we have an error.
@@ -88,73 +85,6 @@ func (i *item) notarize(ctx context.Context, opts *processOptions) error {
8885
lock.Unlock()
8986
}
9087

91-
// If we have a log file, download it. We do this whether we have an error
92-
// or not because the log file can contain more details about the error.
93-
if info != nil && info.LogFileURL != "" {
94-
opts.Logger.Info(
95-
"downloading log file for notarization",
96-
"request_uuid", info.RequestUUID,
97-
"url", info.LogFileURL,
98-
)
99-
100-
log, logerr := notarize.DownloadLog(info.LogFileURL)
101-
opts.Logger.Debug("log file downloaded", "log", log, "err", logerr)
102-
if logerr != nil {
103-
opts.Logger.Warn(
104-
"error downloading log file, this isn't a fatal error",
105-
"err", err,
106-
)
107-
108-
// If we already failed notarization, just return that error
109-
if err := i.State.NotarizeError; err != nil {
110-
return err
111-
}
112-
113-
// If it appears we succeeded notification, we make a new error.
114-
// We can't say notarization is successful without downloading this
115-
// file because warnings will cause notarization to not work
116-
// when loaded.
117-
lock.Lock()
118-
color.New(color.FgRed).Fprintf(os.Stdout,
119-
" %sError downloading log file to verify notarization.\n",
120-
opts.Prefix,
121-
)
122-
lock.Unlock()
123-
124-
return fmt.Errorf(
125-
"Error downloading log file to verify notarization success: %s\n\n"+
126-
"You can download the log file manually at: %s",
127-
logerr, info.LogFileURL,
128-
)
129-
}
130-
131-
// If we have any issues then it is a failed notarization. Notarization
132-
// can "succeed" with warnings, but when you attempt to use/open a file
133-
// Gatekeeper rejects it. So we currently reject any and all issues.
134-
if len(log.Issues) > 0 {
135-
var err error
136-
137-
lock.Lock()
138-
color.New(color.FgRed).Fprintf(os.Stdout,
139-
" %s%d issues during notarization:\n",
140-
opts.Prefix, len(log.Issues))
141-
for idx, issue := range log.Issues {
142-
color.New(color.FgRed).Fprintf(os.Stdout,
143-
" %sIssue #%d (%s) for path %q: %s\n",
144-
opts.Prefix, idx+1, issue.Severity, issue.Path, issue.Message)
145-
146-
// Append the error so we can return it
147-
err = multierror.Append(err, fmt.Errorf(
148-
"%s for path %q: %s",
149-
issue.Severity, issue.Path, issue.Message,
150-
))
151-
}
152-
lock.Unlock()
153-
154-
return err
155-
}
156-
}
157-
15888
// If we aren't notarized, then return
15989
if err := i.State.NotarizeError; err != nil {
16090
return err

cmd/gon/status_human.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type statusHuman struct {
1818
Prefix string
1919
Lock *sync.Mutex
2020

21-
lastStatus string
21+
lastInfoStatus string
22+
lastLogStatus string
2223
}
2324

2425
func (s *statusHuman) Submitting() {
@@ -37,13 +38,23 @@ func (s *statusHuman) Submitted(uuid string) {
3738
os.Stdout, " %sWaiting for results from Apple. This can take minutes to hours.\n", s.Prefix)
3839
}
3940

40-
func (s *statusHuman) Status(info notarize.Info) {
41+
func (s *statusHuman) InfoStatus(info notarize.Info) {
4142
s.Lock.Lock()
4243
defer s.Lock.Unlock()
4344

44-
if info.Status != s.lastStatus {
45-
s.lastStatus = info.Status
46-
color.New().Fprintf(os.Stdout, " %sStatus: %s\n", s.Prefix, info.Status)
45+
if info.Status != s.lastInfoStatus {
46+
s.lastInfoStatus = info.Status
47+
color.New().Fprintf(os.Stdout, " %sInfoStatus: %s\n", s.Prefix, info.Status)
48+
}
49+
}
50+
51+
func (s *statusHuman) LogStatus(log notarize.Log) {
52+
s.Lock.Lock()
53+
defer s.Lock.Unlock()
54+
55+
if log.Status != s.lastLogStatus {
56+
s.lastLogStatus = log.Status
57+
color.New().Fprintf(os.Stdout, " %sLogStatus: %s\n", s.Prefix, log.Status)
4758
}
4859
}
4960

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ go 1.13
55
require (
66
github.com/davecgh/go-spew v1.1.1
77
github.com/fatih/color v1.7.0
8-
github.com/hashicorp/go-cleanhttp v0.5.1
98
github.com/hashicorp/go-hclog v0.9.3-0.20191025211905-234833755cb2
109
github.com/hashicorp/go-multierror v1.0.0
11-
github.com/hashicorp/go-retryablehttp v0.6.3
1210
github.com/hashicorp/hcl/v2 v2.0.0
1311
github.com/sebdah/goldie v1.0.0
1412
github.com/stretchr/testify v1.3.0

go.sum

-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
1515
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
1616
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
1717
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
18-
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
19-
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
20-
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
2118
github.com/hashicorp/go-hclog v0.9.3-0.20191025211905-234833755cb2 h1:STV8OvzphW1vlhPFxcG8d6OIilzBSKRAoWFJt+Onu10=
2219
github.com/hashicorp/go-hclog v0.9.3-0.20191025211905-234833755cb2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
2320
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
2421
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
25-
github.com/hashicorp/go-retryablehttp v0.6.3 h1:tuulM+WnToeqa05z83YLmKabZxrySOmJAd4mJ+s2Nfg=
26-
github.com/hashicorp/go-retryablehttp v0.6.3/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
2722
github.com/hashicorp/hcl/v2 v2.0.0 h1:efQznTz+ydmQXq3BOnRa3AXzvCeTq1P4dKj/z5GLlY8=
2823
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
2924
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=

notarize/info.go

+16-35
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"os/exec"
99
"path/filepath"
10-
"time"
1110

1211
"github.com/hashicorp/go-hclog"
1312
"howett.net/plist"
@@ -23,33 +22,19 @@ type Info struct {
2322
// RequestUUID is the UUID provided by Apple after submitting the
2423
// notarization request. This can be used to look up notarization information
2524
// using the Apple tooling.
26-
RequestUUID string `plist:"RequestUUID"`
25+
RequestUUID string `plist:"id"`
2726

2827
// Date is the date and time of submission
29-
Date time.Time `plist:"Date"`
28+
Date string `plist:"createdDate"`
3029

31-
// Hash is the encoded hash value for the submitted file. This is provided
32-
// by Apple. This is not decoded into a richer type like hash/sha256 because
33-
// it doesn't seem to be guaranteed by Apple anywhere what format this is in.
34-
Hash string `plist:"Hash"`
35-
36-
// LogFileURL is a URL to a log file for more details.
37-
LogFileURL string `plist:"LogFileURL"`
30+
// Name is th file uploaded for submission.
31+
Name string `plist:"name"`
3832

3933
// Status the status of the notarization.
40-
//
41-
// StatusMessage is a human-friendly message associated with a status.
42-
Status string `plist:"Status"`
43-
StatusMessage string `plist:"Status Message"`
44-
}
45-
46-
// infoResult is the structure of the plist emitted directly from
47-
// --notarization-info
48-
type infoResult struct {
49-
Info *Info `plist:"notarization-info"`
34+
Status string `plist:"status"`
5035

51-
// Errors is the list of errors that occurred while uploading
52-
Errors Errors `plist:"product-errors"`
36+
// StatusMessage is a human-friendly message associated with a status.
37+
StatusMessage string `plist:"message"`
5338
}
5439

5540
// info requests the information about a notarization and returns
@@ -78,12 +63,13 @@ func info(ctx context.Context, uuid string, opts *Options) (*Info, error) {
7863

7964
cmd.Args = []string{
8065
filepath.Base(cmd.Path),
81-
"altool",
82-
"--notarization-info",
66+
"notarytool",
67+
"info",
8368
uuid,
84-
"-u", opts.Username,
85-
"-p", opts.Password,
86-
"--output-format", "xml",
69+
"--apple-id", opts.DeveloperId,
70+
"--password", opts.Password,
71+
"--team-id", opts.Provider,
72+
"--output-format", "plist",
8773
}
8874

8975
// We store all output in out for logging and in case there is an error
@@ -109,23 +95,18 @@ func info(ctx context.Context, uuid string, opts *Options) (*Info, error) {
10995

11096
// If we have any output, try to decode that since even in the case of
11197
// an error it will output some information.
112-
var result infoResult
98+
var result Info
11399
if out.Len() > 0 {
114100
if _, perr := plist.Unmarshal(out.Bytes(), &result); perr != nil {
115101
return nil, fmt.Errorf("failed to decode notarization submission output: %w", perr)
116102
}
117103
}
118104

119-
// If there are errors in the result, then show that error
120-
if len(result.Errors) > 0 {
121-
return nil, result.Errors
122-
}
123-
124105
// Now we check the error for actually running the process
125106
if err != nil {
126107
return nil, fmt.Errorf("error checking on notarization status:\n\n%s", combined.String())
127108
}
128109

129-
logger.Info("notarization info", "uuid", uuid, "info", result.Info)
130-
return result.Info, nil
110+
logger.Info("notarization info", "uuid", uuid, "info", result)
111+
return &result, nil
131112
}

0 commit comments

Comments
 (0)