Skip to content

Commit 603a30a

Browse files
authored
Set current team id after spaceship login on the spaceship client (#227)
* Set current team id after spaceship login on the spaceship client * Extract team id from sapecship respone * Update current team related log
1 parent b742e10 commit 603a30a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

autocodesign/devportalclient/spaceship/spaceship.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,35 @@ func NewClient(authConfig appleauth.AppleID, teamID string, cmdFactory ruby.Comm
5050
cmdFactory: cmdFactory,
5151
}
5252

53-
_, err = c.runSpaceshipCommand("login")
53+
currentTeamID, err := c.login()
5454
if err != nil {
55-
return nil, fmt.Errorf("running command failed with error: %s", err)
55+
return nil, fmt.Errorf("spaceship command failed: %s", err)
5656
}
5757

58+
log.Debugf("current team id: %s", currentTeamID)
59+
60+
c.teamID = currentTeamID
61+
5862
return c, nil
5963
}
6064

65+
func (c *Client) login() (string, error) {
66+
output, err := c.runSpaceshipCommand("login")
67+
if err != nil {
68+
return "", fmt.Errorf("running command failed with error: %s", err)
69+
}
70+
71+
// {"data":"72SA8V3WYL"}
72+
var teamIDResponse struct {
73+
Data string `json:"data"`
74+
}
75+
if err := json.Unmarshal([]byte(output), &teamIDResponse); err != nil {
76+
return "", fmt.Errorf("failed to unmarshal response: %v", err)
77+
}
78+
79+
return teamIDResponse.Data, nil
80+
}
81+
6182
// DevPortalClient ...
6283
type DevPortalClient struct {
6384
*CertificateSource

autocodesign/devportalclient/spaceship/spaceship/main.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@
2727

2828
FastlaneCore::Globals.verbose = true
2929

30+
result = '{}'
31+
3032
if options[:subcommand] == 'login'
3133
begin
32-
Portal::AuthClient.login(options[:username], options[:password], options[:session], options[:team_id])
34+
team_id = Portal::AuthClient.login(options[:username], options[:password], options[:session], options[:team_id])
35+
result = team_id
3336
rescue => e
3437
puts "\nApple ID authentication failed: #{e}"
3538
exit(1)
3639
end
3740
else
3841
Portal::AuthClient.restore_from_session(options[:username], options[:team_id])
3942

40-
result = '{}'
4143
case options[:subcommand]
4244
when 'list_dev_certs'
4345
client = CertificateHelper.new

autocodesign/devportalclient/spaceship/spaceship/portal/auth_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def self.login(username, password, two_factor_session = nil, team_id = nil)
1717
end
1818

1919
client.store_cookie
20+
21+
client.team_id
2022
end
2123

2224
def self.restore_from_session(username, team_id)

0 commit comments

Comments
 (0)