Documentation
¶
Index ¶
- Variables
- type APIKeyAttributes
- type APIKeyResource
- type Application
- type ApplicationAttributes
- type ApplicationResource
- type ApplicationsResponse
- type Client
- func (c *Client) AuthorizationCodeGrant(code, codeVerifier, redirectURI string) (*OAuthTokenResponse, error)
- func (c *Client) AuthorizeURL(codeChallenge, redirectURI string) string
- func (c *Client) CreateAPIKey(accessToken, appID string, acl []string, description string) (string, error)
- func (c *Client) CreateApplication(accessToken, region, name string) (*Application, error)
- func (c *Client) GetApplication(accessToken, appID string) (*Application, error)
- func (c *Client) ListApplications(accessToken string) ([]Application, error)
- func (c *Client) ListRegions(accessToken string) ([]Region, error)
- func (c *Client) RefreshToken(refreshToken string) (*OAuthTokenResponse, error)
- func (c *Client) RevokeToken(token string) error
- func (c *Client) SignupAuthorizeURL(codeChallenge, redirectURI string) string
- type CreateAPIKeyRequest
- type CreateAPIKeyResponse
- type CreateApplicationRequest
- type ErrClusterUnavailable
- type OAuthErrorResponse
- type OAuthTokenResponse
- type Region
- type RegionsResponse
- type SingleApplicationResponse
- type User
Constants ¶
This section is empty.
Variables ¶
var ( DefaultDashboardURL = "" DefaultAPIURL = "" DefaultOAuthScope = "" )
DefaultDashboardURL and DefaultAPIURL are empty by default and must be injected at build time via ldflags, e.g.:
go build -ldflags "-X github.com/algolia/cli/api/dashboard.DefaultDashboardURL=https://..."
They can also be overridden at runtime with ALGOLIA_DASHBOARD_URL / ALGOLIA_API_URL / ALGOLIA_OAUTH_SCOPE environment variables.
var ErrSessionExpired = errors.New("session expired")
ErrSessionExpired is returned when an API call gets a 401 Unauthorized.
var WriteACL = []string{
"search", "browse", "seeUnretrievableAttributes", "listIndexes",
"analytics", "logs", "addObject", "deleteObject", "deleteIndex",
"settings", "editSettings", "recommendation",
}
WriteACL is the set of permissions for API keys created by the CLI.
Functions ¶
This section is empty.
Types ¶
type APIKeyAttributes ¶
type APIKeyAttributes struct {
Value string `json:"value"`
}
APIKeyAttributes contains the actual API key fields.
type APIKeyResource ¶
type APIKeyResource struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes APIKeyAttributes `json:"attributes"`
}
APIKeyResource is a JSON:API resource wrapper for an API key.
type Application ¶
type Application struct {
ID string `json:"id"`
Name string `json:"name"`
APIKey string `json:"api_key,omitempty"`
}
Application is a flattened view of an Algolia application for CLI consumption.
type ApplicationAttributes ¶
type ApplicationAttributes struct {
Name string `json:"name"`
ApplicationID string `json:"application_id"`
APIKey string `json:"api_key"`
}
ApplicationAttributes contains the actual application fields.
type ApplicationResource ¶
type ApplicationResource struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes ApplicationAttributes `json:"attributes"`
}
ApplicationResource is a JSON:API resource wrapper for an application.
type ApplicationsResponse ¶
type ApplicationsResponse struct {
Data []ApplicationResource `json:"data"`
}
ApplicationsResponse is the JSON:API response from GET /1/applications.
type Client ¶
type Client struct {
DashboardURL string
APIURL string
OAuthScope string
ClientID string
// contains filtered or unexported fields
}
Client interacts with the Algolia Dashboard OAuth endpoint and the Public API.
func NewClient ¶
NewClient creates a new dashboard client with the given OAuth client ID. Respects ALGOLIA_DASHBOARD_URL, ALGOLIA_API_URL, and ALGOLIA_OAUTH_SCOPE environment variables, falling back to the compiled-in defaults (set via ldflags).
func NewClientWithHTTPClient ¶
NewClientWithHTTPClient creates a new dashboard client with a custom HTTP client. Used primarily in tests; callers must set DashboardURL and APIURL explicitly.
func (*Client) AuthorizationCodeGrant ¶
func (c *Client) AuthorizationCodeGrant(code, codeVerifier, redirectURI string) (*OAuthTokenResponse, error)
AuthorizationCodeGrant exchanges an authorization code + PKCE code_verifier for an access token. The redirectURI must match the one used in the authorize URL.
func (*Client) AuthorizeURL ¶
AuthorizeURL builds the OAuth 2.0 authorization URL for the browser-based sign-in flow.
func (*Client) CreateAPIKey ¶
func (c *Client) CreateAPIKey(accessToken, appID string, acl []string, description string) (string, error)
CreateAPIKey creates a new API key with the given ACL for the specified application.
func (*Client) CreateApplication ¶
func (c *Client) CreateApplication(accessToken, region, name string) (*Application, error)
CreateApplication creates a new application for the authenticated user.
func (*Client) GetApplication ¶
func (c *Client) GetApplication(accessToken, appID string) (*Application, error)
GetApplication returns a single application by its ID.
func (*Client) ListApplications ¶
func (c *Client) ListApplications(accessToken string) ([]Application, error)
ListApplications returns all applications for the authenticated user.
func (*Client) ListRegions ¶
ListRegions returns the allowed hosting regions for application creation.
func (*Client) RefreshToken ¶
func (c *Client) RefreshToken(refreshToken string) (*OAuthTokenResponse, error)
RefreshToken uses a refresh token to obtain a new access token.
func (*Client) RevokeToken ¶
RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke.
func (*Client) SignupAuthorizeURL ¶
SignupAuthorizeURL builds an OAuth 2.0 authorization URL that opens the sign-up page instead of the default sign-in page.
type CreateAPIKeyRequest ¶
type CreateAPIKeyRequest struct {
ACL []string `json:"acl"`
Description string `json:"description"`
}
CreateAPIKeyRequest is the payload for POST /1/applications/{application_id}/api-keys.
type CreateAPIKeyResponse ¶
type CreateAPIKeyResponse struct {
Data APIKeyResource `json:"data"`
}
CreateAPIKeyResponse is the JSON:API response from POST /1/applications/{application_id}/api-keys.
type CreateApplicationRequest ¶
type CreateApplicationRequest struct {
RegionCode string `json:"region_code"`
Name string `json:"name"`
}
CreateApplicationRequest is the payload for POST /1/applications.
type ErrClusterUnavailable ¶
type ErrClusterUnavailable struct {
}
ErrClusterUnavailable is returned when a region has no available cluster.
func (*ErrClusterUnavailable) Error ¶
func (e *ErrClusterUnavailable) Error() string
type OAuthErrorResponse ¶
type OAuthErrorResponse struct {
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
}
OAuthErrorResponse is the error format from the OAuth endpoints.
type OAuthTokenResponse ¶
type OAuthTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
CreatedAt int64 `json:"created_at"`
User *User `json:"user,omitempty"`
}
OAuthTokenResponse is the response from POST /2/oauth/token.
type RegionsResponse ¶
type RegionsResponse struct {
RegionCodes []Region `json:"region_codes"`
}
RegionsResponse is the response from GET /1/hosting/regions.
type SingleApplicationResponse ¶
type SingleApplicationResponse struct {
Data ApplicationResource `json:"data"`
}
SingleApplicationResponse is the JSON:API response from GET /1/application/:id.