This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
config.go
104 lines (87 loc) · 3.47 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"strings"
"github.com/bitrise-io/go-steputils/v2/stepconf"
"github.com/bitrise-io/go-utils/sliceutil"
"github.com/bitrise-io/go-xcode/appleauth"
"github.com/bitrise-io/go-xcode/v2/autocodesign"
"github.com/bitrise-io/go-xcode/v2/autocodesign/certdownloader"
)
// Config holds the step inputs
type Config struct {
BitriseConnection string `env:"connection,opt[automatic,api_key,off,enterprise_with_apple_id,enterprise-with-apple-id,apple_id,apple-id]"`
APIKeyPath stepconf.Secret `env:"api_key_path"`
APIIssuer string `env:"api_issuer"`
// Apple ID
TeamID string `env:"apple_id_team_id"`
ProjectPath string `env:"project_path,dir"`
Scheme string `env:"scheme,required"`
Configuration string `env:"configuration"`
SignUITestTargets bool `env:"sign_uitest_targets,opt[yes,no]"`
RegisterTestDevices bool `env:"register_test_devices,opt[yes,no]"`
Distribution string `env:"distribution_type,opt[development,app-store,ad-hoc,enterprise]"`
MinProfileDaysValid int `env:"min_profile_days_valid"`
CertificateURLList string `env:"certificate_urls,required"`
CertificatePassphraseList stepconf.Secret `env:"passphrases"`
KeychainPath string `env:"keychain_path,required"`
KeychainPassword stepconf.Secret `env:"keychain_password,required"`
VerboseLog bool `env:"verbose_log,opt[no,yes]"`
BuildAPIToken string `env:"build_api_token"`
BuildURL string `env:"build_url"`
}
// DistributionType ...
func (c Config) DistributionType() autocodesign.DistributionType {
return autocodesign.DistributionType(c.Distribution)
}
// ValidateCertificates validates if the number of certificate URLs matches those of passphrases
func (c Config) ValidateCertificates() ([]string, []string, error) {
pfxURLs := splitAndClean(c.CertificateURLList, "|", true)
passphrases := splitAndClean(string(c.CertificatePassphraseList), "|", false)
if len(pfxURLs) != len(passphrases) {
return nil, nil, fmt.Errorf("certificates count (%d) and passphrases count (%d) should match", len(pfxURLs), len(passphrases))
}
return pfxURLs, passphrases, nil
}
// Certificates returns an array of p12 file URLs and passphrases
func (c Config) Certificates() ([]certdownloader.CertificateAndPassphrase, error) {
pfxURLs, passphrases, err := c.ValidateCertificates()
if err != nil {
return nil, err
}
files := make([]certdownloader.CertificateAndPassphrase, len(pfxURLs))
for i, pfxURL := range pfxURLs {
files[i] = certdownloader.CertificateAndPassphrase{
URL: pfxURL,
Passphrase: passphrases[i],
}
}
return files, nil
}
// SplitAndClean ...
func splitAndClean(list string, sep string, omitEmpty bool) (items []string) {
return sliceutil.CleanWhitespace(strings.Split(list, sep), omitEmpty)
}
func parseAuthSources(bitriseConnection string) ([]appleauth.Source, error) {
switch bitriseConnection {
case "automatic":
return []appleauth.Source{
&appleauth.ConnectionAPIKeySource{},
&appleauth.InputAPIKeySource{},
}, nil
case "api_key":
return []appleauth.Source{
&appleauth.ConnectionAPIKeySource{},
}, nil
case "apple_id", "apple-id", "enterprise_with_apple_id", "enterprise-with-apple-id":
return []appleauth.Source{
&appleauth.ConnectionAppleIDFastlaneSource{},
}, nil
case "off":
return []appleauth.Source{
&appleauth.InputAPIKeySource{},
}, nil
default:
return nil, fmt.Errorf("invalid connection input: %s", bitriseConnection)
}
}