From 878a898d4cdecd4958f96a917f141c0b945391ca Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 13 Aug 2024 23:41:12 +0100 Subject: [PATCH] fix: use VerifyCredentials to get account info Use the clients VerifyCredentials method to get the user's account information. --- internal/executor/account.go | 17 ++++------------- internal/executor/show.go | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/internal/executor/account.go b/internal/executor/account.go index 6660a37..d1086f6 100644 --- a/internal/executor/account.go +++ b/internal/executor/account.go @@ -4,7 +4,6 @@ import ( "fmt" "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" "codeflow.dananglin.me.uk/apollo/enbas/internal/model" ) @@ -15,7 +14,7 @@ func getAccountID( accountNames internalFlag.StringSliceValue, credentialsFile string, ) (string, error) { - account, err := getAccount(gtsClient, myAccount, accountNames, credentialsFile) + account, err := getAccount(gtsClient, myAccount, accountNames) if err != nil { return "", fmt.Errorf("unable to get the account information: %w", err) } @@ -27,7 +26,6 @@ func getAccount( gtsClient *client.Client, myAccount bool, accountNames internalFlag.StringSliceValue, - credentialsFile string, ) (model.Account, error) { var ( account model.Account @@ -36,7 +34,7 @@ func getAccount( switch { case myAccount: - account, err = getMyAccount(gtsClient, credentialsFile) + account, err = getMyAccount(gtsClient) if err != nil { return account, fmt.Errorf("unable to get your account ID: %w", err) } @@ -52,15 +50,8 @@ func getAccount( return account, nil } -func getMyAccount(gtsClient *client.Client, path string) (model.Account, error) { - authConfig, err := config.NewCredentialsConfigFromFile(path) - if err != nil { - return model.Account{}, fmt.Errorf("unable to retrieve the authentication configuration: %w", err) - } - - accountURI := authConfig.CurrentAccount - - account, err := gtsClient.GetAccount(accountURI) +func getMyAccount(gtsClient *client.Client) (model.Account, error) { + account, err := gtsClient.VerifyCredentials() if err != nil { return model.Account{}, fmt.Errorf("unable to retrieve your account: %w", err) } diff --git a/internal/executor/show.go b/internal/executor/show.go index fafc692..b9499a6 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -59,7 +59,7 @@ func (s *ShowExecutor) showInstance(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 { return fmt.Errorf("unable to get the account information: %w", err) }