Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions cli/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ func (c *RegisterCmd) RunE(_ *cobra.Command, args []string) error {
}

func (c *RegisterCmd) Register(p portal.Portal) error {
expiresAt, err := time.Parse(time.RFC3339, c.Opts.ExpiresAt)
if err != nil {
return fmt.Errorf("failed to parse expiration date: %w", err)
var err error
var expiresAt time.Time
if c.Opts.ExpiresAt != "" {
expiresAt, err = time.Parse(time.RFC3339, c.Opts.ExpiresAt)
if err != nil {
return fmt.Errorf("failed to parse expiration date: %w", err)
}
}

err = p.RegisterAPIKey(c.Opts.Owner, c.Opts.Organization, c.Opts.Role, expiresAt)
Expand Down
5 changes: 5 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func GetRootCmd() *cobra.Command {
AddUpdateCmd(rootCmd)
AddListCmd(rootCmd, opts)
AddDownloadCmd(rootCmd, opts)

// OMS API key management commands
AddRegisterCmd(rootCmd, opts)
AddRevokeCmd(rootCmd, opts)

return rootCmd
}

Expand Down
6 changes: 3 additions & 3 deletions internal/portal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *PortalClient) HttpRequest(method string, path string, body []byte) (res
fmt.Println("If you already have an API Key, make sure to set it using the environment variable OMS_PORTAL_API_KEY")
}
var respBody []byte
if resp.StatusCode != http.StatusOK {
if resp.StatusCode >= 300 {
if resp.Body != nil {
respBody, _ = io.ReadAll(resp.Body)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (c *PortalClient) RegisterAPIKey(owner string, organization string, role st
return fmt.Errorf("failed to generate request body: %w", err)
}

resp, err := c.HttpRequest(http.MethodPost, "/api/key/register", reqBody)
resp, err := c.HttpRequest(http.MethodPost, "/key/register", reqBody)
if err != nil {
return fmt.Errorf("POST request to register API key failed: %w", err)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (c *PortalClient) RevokeAPIKey(key string) error {
return fmt.Errorf("failed to generate request body: %w", err)
}

resp, err := c.HttpRequest(http.MethodPost, "/api/key/revoke", reqBody)
resp, err := c.HttpRequest(http.MethodPost, "/key/revoke", reqBody)
if err != nil {
return fmt.Errorf("POST request to revoke API key failed: %w", err)
}
Expand Down