fix: use VerifyCredentials to get account info
Use the clients VerifyCredentials method to get the user's account information.
This commit is contained in:
parent
b77bbaa6e0
commit
878a898d4c
2 changed files with 5 additions and 14 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
|
||||||
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +14,7 @@ func getAccountID(
|
||||||
accountNames internalFlag.StringSliceValue,
|
accountNames internalFlag.StringSliceValue,
|
||||||
credentialsFile string,
|
credentialsFile string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
account, err := getAccount(gtsClient, myAccount, accountNames, credentialsFile)
|
account, err := getAccount(gtsClient, myAccount, accountNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to get the account information: %w", err)
|
return "", fmt.Errorf("unable to get the account information: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +26,6 @@ func getAccount(
|
||||||
gtsClient *client.Client,
|
gtsClient *client.Client,
|
||||||
myAccount bool,
|
myAccount bool,
|
||||||
accountNames internalFlag.StringSliceValue,
|
accountNames internalFlag.StringSliceValue,
|
||||||
credentialsFile string,
|
|
||||||
) (model.Account, error) {
|
) (model.Account, error) {
|
||||||
var (
|
var (
|
||||||
account model.Account
|
account model.Account
|
||||||
|
@ -36,7 +34,7 @@ func getAccount(
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case myAccount:
|
case myAccount:
|
||||||
account, err = getMyAccount(gtsClient, credentialsFile)
|
account, err = getMyAccount(gtsClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return account, fmt.Errorf("unable to get your account ID: %w", err)
|
return account, fmt.Errorf("unable to get your account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -52,15 +50,8 @@ func getAccount(
|
||||||
return account, nil
|
return account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMyAccount(gtsClient *client.Client, path string) (model.Account, error) {
|
func getMyAccount(gtsClient *client.Client) (model.Account, error) {
|
||||||
authConfig, err := config.NewCredentialsConfigFromFile(path)
|
account, err := gtsClient.VerifyCredentials()
|
||||||
if err != nil {
|
|
||||||
return model.Account{}, fmt.Errorf("unable to retrieve the authentication configuration: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountURI := authConfig.CurrentAccount
|
|
||||||
|
|
||||||
account, err := gtsClient.GetAccount(accountURI)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.Account{}, fmt.Errorf("unable to retrieve your account: %w", err)
|
return model.Account{}, fmt.Errorf("unable to retrieve your account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (s *ShowExecutor) showInstance(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
||||||
account, err := getAccount(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
account, err := getAccount(gtsClient, s.myAccount, s.accountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account information: %w", err)
|
return fmt.Errorf("unable to get the account information: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue