account_oauth_client.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  )
   6  
   7  // OAuthClientStatus constants start with OAuthClient and include Linode API Instance Status values
   8  type OAuthClientStatus string
   9  
  10  // OAuthClientStatus constants reflect the current status of an OAuth Client
  11  const (
  12  	OAuthClientActive    OAuthClientStatus = "active"
  13  	OAuthClientDisabled  OAuthClientStatus = "disabled"
  14  	OAuthClientSuspended OAuthClientStatus = "suspended"
  15  )
  16  
  17  // OAuthClient represents a OAuthClient object
  18  type OAuthClient struct {
  19  	// The unique ID of this OAuth Client.
  20  	ID string `json:"id"`
  21  
  22  	// The location a successful log in from https://login.linode.com should be redirected to for this client. The receiver of this redirect should be ready to accept an OAuth exchange code and finish the OAuth exchange.
  23  	RedirectURI string `json:"redirect_uri"`
  24  
  25  	// The name of this application. This will be presented to users when they are asked to grant it access to their Account.
  26  	Label string `json:"label"`
  27  
  28  	// Current status of the OAuth Client, Enum: "active" "disabled" "suspended"
  29  	Status OAuthClientStatus `json:"status"`
  30  
  31  	// The OAuth Client secret, used in the OAuth exchange. This is returned as <REDACTED> except when an OAuth Client is created or its secret is reset. This is a secret, and should not be shared or disclosed publicly.
  32  	Secret string `json:"secret"`
  33  
  34  	// If this OAuth Client is public or private.
  35  	Public bool `json:"public"`
  36  
  37  	// The URL where this client's thumbnail may be viewed, or nil if this client does not have a thumbnail set.
  38  	ThumbnailURL *string `json:"thumbnail_url"`
  39  }
  40  
  41  // OAuthClientCreateOptions fields are those accepted by CreateOAuthClient
  42  type OAuthClientCreateOptions struct {
  43  	// The location a successful log in from https://login.linode.com should be redirected to for this client. The receiver of this redirect should be ready to accept an OAuth exchange code and finish the OAuth exchange.
  44  	RedirectURI string `json:"redirect_uri"`
  45  
  46  	// The name of this application. This will be presented to users when they are asked to grant it access to their Account.
  47  	Label string `json:"label"`
  48  
  49  	// If this OAuth Client is public or private.
  50  	Public bool `json:"public"`
  51  }
  52  
  53  // OAuthClientUpdateOptions fields are those accepted by UpdateOAuthClient
  54  type OAuthClientUpdateOptions struct {
  55  	// The location a successful log in from https://login.linode.com should be redirected to for this client. The receiver of this redirect should be ready to accept an OAuth exchange code and finish the OAuth exchange.
  56  	RedirectURI string `json:"redirect_uri"`
  57  
  58  	// The name of this application. This will be presented to users when they are asked to grant it access to their Account.
  59  	Label string `json:"label"`
  60  
  61  	// If this OAuth Client is public or private.
  62  	Public bool `json:"public"`
  63  }
  64  
  65  // GetCreateOptions converts a OAuthClient to OAuthClientCreateOptions for use in CreateOAuthClient
  66  func (i OAuthClient) GetCreateOptions() (o OAuthClientCreateOptions) {
  67  	o.RedirectURI = i.RedirectURI
  68  	o.Label = i.Label
  69  	o.Public = i.Public
  70  
  71  	return o
  72  }
  73  
  74  // GetUpdateOptions converts a OAuthClient to OAuthClientUpdateOptions for use in UpdateOAuthClient
  75  func (i OAuthClient) GetUpdateOptions() (o OAuthClientUpdateOptions) {
  76  	o.RedirectURI = i.RedirectURI
  77  	o.Label = i.Label
  78  	o.Public = i.Public
  79  
  80  	return o
  81  }
  82  
  83  // ListOAuthClients lists OAuthClients
  84  func (c *Client) ListOAuthClients(ctx context.Context, opts *ListOptions) ([]OAuthClient, error) {
  85  	return getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
  86  }
  87  
  88  // GetOAuthClient gets the OAuthClient with the provided ID
  89  func (c *Client) GetOAuthClient(ctx context.Context, clientID string) (*OAuthClient, error) {
  90  	e := formatAPIPath("account/oauth-clients/%s", clientID)
  91  	return doGETRequest[OAuthClient](ctx, c, e)
  92  }
  93  
  94  // CreateOAuthClient creates an OAuthClient
  95  func (c *Client) CreateOAuthClient(ctx context.Context, opts OAuthClientCreateOptions) (*OAuthClient, error) {
  96  	return doPOSTRequest[OAuthClient](ctx, c, "account/oauth-clients", opts)
  97  }
  98  
  99  // UpdateOAuthClient updates the OAuthClient with the specified id
 100  func (c *Client) UpdateOAuthClient(ctx context.Context, clientID string, opts OAuthClientUpdateOptions) (*OAuthClient, error) {
 101  	e := formatAPIPath("account/oauth-clients/%s", clientID)
 102  	return doPUTRequest[OAuthClient](ctx, c, e, opts)
 103  }
 104  
 105  // DeleteOAuthClient deletes the OAuthClient with the specified id
 106  func (c *Client) DeleteOAuthClient(ctx context.Context, clientID string) error {
 107  	e := formatAPIPath("account/oauth-clients/%s", clientID)
 108  	return doDELETERequest(ctx, c, e)
 109  }
 110  
 111  // ResetOAuthClientSecret resets the OAuth Client secret for a client with a specified id
 112  func (c *Client) ResetOAuthClientSecret(ctx context.Context, clientID string) (*OAuthClient, error) {
 113  	e := formatAPIPath("account/oauth-clients/%s/reset-secret", clientID)
 114  	return doPOSTRequest[OAuthClient, any](ctx, c, e)
 115  }
 116