Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/portal/api_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package portal

import "time"

type ApiKey struct {
RID string `json:"rid"`
ApiKey string `json:"api_key"`
Owner string `json:"owner"`
Organization string `json:"organization"`
Role string `json:"role"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
13 changes: 8 additions & 5 deletions internal/portal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,21 @@ func (c *PortalClient) RegisterAPIKey(owner string, organization string, role st
}
defer func() { _ = resp.Body.Close() }()

var newKey string
err = json.NewDecoder(resp.Body).Decode(&newKey)
newKey := &ApiKey{}
err = json.NewDecoder(resp.Body).Decode(newKey)
if err != nil {
return fmt.Errorf("failed to decode response body: %w", err)
}

fmt.Printf("API key for owner %s registered successfully: %s\n", owner, newKey)
fmt.Println("API key registered successfully!")
fmt.Printf("Owner: %s\nOrganisation: %s\nKey: %s\n", newKey.Owner, newKey.Organization, newKey.ApiKey)

return nil
}

func (c *PortalClient) RevokeAPIKey(key string) error {
req := struct {
Key string `json:"key"`
Key string `json:"api_key"`
}{
Key: key,
}
Expand All @@ -250,6 +252,7 @@ func (c *PortalClient) RevokeAPIKey(key string) error {
}
defer func() { _ = resp.Body.Close() }()

fmt.Println("API key revoked successfully")
fmt.Println("API key revoked successfully!")

return nil
}