Skip to content

Commit

Permalink
Make mage integration:auth work again (#4996)
Browse files Browse the repository at this point in the history
* Update ESS API

* Update UI location
  • Loading branch information
ycombinator authored Jun 25, 2024
1 parent ce5d51c commit 727eb6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3065,12 +3065,12 @@ func authESS(ctx context.Context) error {
// Attempt to use API key to check if it's valid
for authSuccess := false; !authSuccess; {
client := ess.NewClient(ess.Config{ApiKey: essAPIKey})
u, err := client.GetUser(ctx, ess.GetUserRequest{})
u, err := client.GetAccount(ctx, ess.GetAccountRequest{})
if err != nil {
return fmt.Errorf("unable to successfully connect to ESS API: %w", err)
}

if u.User.UserID != 0 {
if u.ID != "" {
// We have a user. It indicates that the API key works. All set!
authSuccess = true
continue
Expand All @@ -3079,7 +3079,7 @@ func authESS(ctx context.Context) error {
fmt.Fprintln(os.Stderr, "❌ ESS authentication unsuccessful. Retrying...")

prompt := fmt.Sprintf("Please provide a ESS API key for %s. To get your API key, "+
"visit %s/deployment-features/keys:", client.BaseURL(), strings.TrimRight(client.BaseURL(), "/api/v1"))
"visit %s/account/keys:", client.BaseURL(), strings.TrimRight(client.BaseURL(), "/api/v1"))
essAPIKey, err = stringPrompt(prompt)
if err != nil {
return fmt.Errorf("unable to read ESS API key from prompt: %w", err)
Expand Down
16 changes: 7 additions & 9 deletions pkg/testing/ess/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import (
"fmt"
)

type GetUserRequest struct {
type GetAccountRequest struct {
// For future use
}

type GetUserResponse struct {
User struct {
UserID int `json:"user_id"`
} `json:"user"`
type GetAccountResponse struct {
ID string `json:"id"`
}

// GetUser returns information about the authenticated user
func (c *Client) GetUser(ctx context.Context, req GetUserRequest) (*GetUserResponse, error) {
resp, err := c.doGet(ctx, "users")
// GetAccount returns information about the authenticated user
func (c *Client) GetAccount(ctx context.Context, req GetAccountRequest) (*GetAccountResponse, error) {
resp, err := c.doGet(ctx, "account")
if err != nil {
return nil, fmt.Errorf("error calling get user API: %w", err)
}
defer resp.Body.Close()

var respBody GetUserResponse
var respBody GetAccountResponse
if err := json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
return nil, fmt.Errorf("error parsing get user response: %w", err)
}
Expand Down

0 comments on commit 727eb6a

Please sign in to comment.