Skip to content

Commit

Permalink
fix(acr-ee): fix get instanceId via ListInstance sometimes may not work
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Sep 1, 2024
1 parent 950178c commit 2ca0d65
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/acr/ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ func (c *eeClient) getInstanceId(instanceName string) (string, error) {
return "", fmt.Errorf("get ACR EE instance id for name %q failed: %s", instanceName, resp.Body.String())
}
instances := resp.Body.Instances
if len(instances) == 0 {
return "", fmt.Errorf("get ACR EE instance id for name %q failed: instance name is not found", instanceName)
for _, item := range instances {
if tea.StringValue(item.InstanceName) == instanceName {
return tea.StringValue(item.InstanceId), nil
}
}

return tea.StringValue(instances[0].InstanceId), nil
return "", fmt.Errorf("get ACR EE instance id for name %q failed: instance name is not found", instanceName)
}

func (c *eeClient) getCredentials(instanceId string) (*Credentials, error) {
Expand All @@ -73,7 +75,7 @@ func (c *eeClient) getCredentials(instanceId string) (*Credentials, error) {
cred := &Credentials{
UserName: tea.StringValue(resp.Body.TempUsername),
Password: tea.StringValue(resp.Body.AuthorizationToken),
ExpireTime: expTime,
ExpireTime: expTime.Add(-time.Minute),
}
return cred, nil
}

0 comments on commit 2ca0d65

Please sign in to comment.