Documentation
¶
Index ¶
- Constants
- Variables
- type APIKeyAttributes
- type APIKeyResource
- type Application
- type ApplicationAttributes
- type ApplicationPlan
- type ApplicationResource
- type ApplicationsResponse
- type ChangePlanRequest
- type Client
- func (c *Client) AuthorizationCodeGrant(code, codeVerifier, redirectURI string) (*OAuthTokenResponse, error)
- func (c *Client) AuthorizeURL(codeChallenge, redirectURI string) string
- func (c *Client) ChangeApplicationPlan(accessToken, appID, plan string) (*Application, error)
- 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) GetCrawlerUser(accessToken string) (*DashboardCrawlerUserData, error)
- func (c *Client) GetSelfServePlans(accessToken string) ([]Plan, error)
- func (c *Client) GetUser(accessToken string) (*DashboardUser, 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
- func (c *Client) UpdateApplication(accessToken, appID, name string) (*Application, error)
- type CreateAPIKeyRequest
- type CreateAPIKeyResponse
- type CreateApplicationRequest
- type DashboardCrawlerError
- type DashboardCrawlerErrorResponse
- type DashboardCrawlerUserData
- type DashboardCrawlerUserResponse
- type DashboardUser
- type ErrClusterUnavailable
- type OAuthErrorResponse
- type OAuthTokenResponse
- type PaginationLinks
- type PaginationMeta
- type Plan
- type PlanTemplateAttributes
- type PlanTemplateConfiguration
- type PlanTemplateResource
- type PlanTemplatesResponse
- type Region
- type RegionsResponse
- type SingleApplicationResponse
- type UpdateApplicationRequest
- type User
Constants ¶
const PlanTypeFree = "free"
PlanTypeFree is the attributes.type value that identifies the free-tier plan template. The free plan's configuration.plan id is not fixed (it can be "build"), so the CLI keys off this type rather than a hard-coded id when it needs to map the user-facing "free" choice to a concrete plan.
Variables ¶
var ( DefaultDashboardURL = "https://dashboard.algolia.com" DefaultAPIURL = "https://api.dashboard.algolia.com" DefaultOAuthScope = "public applications:manage keys:manage" )
Production defaults; overridable via ldflags or ALGOLIA_DASHBOARD_URL / ALGOLIA_API_URL / ALGOLIA_OAUTH_SCOPE env vars.
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"`
PlanLabel string `json:"plan_label,omitempty"` // current plan label, e.g. "Grow Plus"
}
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"`
Plan ApplicationPlan `json:"plan"`
}
ApplicationAttributes contains the actual application fields.
type ApplicationPlan ¶ added in v1.11.0
type ApplicationPlan struct {
Name string `json:"name"`
Label string `json:"label"`
Version int `json:"version"`
PayAsYouGo bool `json:"pay_as_you_go"`
}
ApplicationPlan is the plan applied to an application (attributes.plan). Label (e.g. "Grow Plus") matches a self-serve plan template's Name.
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"`
Meta PaginationMeta `json:"meta"`
Links PaginationLinks `json:"links"`
}
ApplicationsResponse is the JSON:API response from GET /1/applications.
type ChangePlanRequest ¶ added in v1.11.0
type ChangePlanRequest struct {
Plan string `json:"plan"`
}
ChangePlanRequest is the payload for PATCH /1/applications/{id}/plan/self-serve.
Every request body in this client is a plain JSON object (see CreateApplicationRequest and UpdateApplicationRequest) rather than a JSON:API data.attributes envelope, so we mirror that existing convention here.
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) ChangeApplicationPlan ¶ added in v1.11.0
func (c *Client) ChangeApplicationPlan(accessToken, appID, plan string) (*Application, error)
ChangeApplicationPlan changes the plan of an application
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) GetCrawlerUser ¶ added in v1.8.3
func (c *Client) GetCrawlerUser(accessToken string) (*DashboardCrawlerUserData, error)
GetCrawlerUser gets the crawler API user data for the current authenticated user
func (*Client) GetSelfServePlans ¶ added in v1.11.0
GetSelfServePlans returns the available plans
func (*Client) GetUser ¶ added in v1.11.0
func (c *Client) GetUser(accessToken string) (*DashboardUser, error)
GetUser returns account-level information for the authenticated user
func (*Client) ListApplications ¶
func (c *Client) ListApplications(accessToken string) ([]Application, error)
ListApplications returns all applications for the authenticated user, following pagination to fetch every page.
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.
func (*Client) UpdateApplication ¶ added in v1.11.0
func (c *Client) UpdateApplication(accessToken, appID, name string) (*Application, error)
UpdateApplication renames an existing application.
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 DashboardCrawlerError ¶ added in v1.8.3
type DashboardCrawlerErrorResponse ¶ added in v1.8.3
type DashboardCrawlerErrorResponse struct {
Errors []DashboardCrawlerError `json:"errors"`
}
type DashboardCrawlerUserData ¶ added in v1.8.3
type DashboardCrawlerUserData struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
APIKey string `json:"apiKey"`
}
DashboardCrawlerUserData contains the user information from the crawler API
type DashboardCrawlerUserResponse ¶ added in v1.8.3
type DashboardCrawlerUserResponse struct {
Data DashboardCrawlerUserData `json:"data"`
}
DashboardCrawlerUserResponse is the JSON:API response from GET /1/crawler/user
type DashboardUser ¶ added in v1.11.0
type DashboardUser struct {
HasPaymentMethod bool `json:"has_payment_method"`
}
DashboardUser is a flattened view of the authenticated user's account info from GET /1/user, exposing only what plan changes need.
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 PaginationLinks ¶ added in v1.8.1
type PaginationLinks struct {
First string `json:"first"`
Last string `json:"last"`
Prev string `json:"prev"`
Next string `json:"next"`
}
PaginationLinks contains pagination URLs.
type PaginationMeta ¶ added in v1.8.1
type PaginationMeta struct {
TotalCount int `json:"total_count"`
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
}
PaginationMeta contains page-based pagination metadata.
type Plan ¶ added in v1.11.0
type Plan struct {
ID string `json:"id"` // configuration.plan (e.g. "build", "grow", "grow-plus")
Name string `json:"name"` // human-readable name (e.g. "Grow Plus")
Description string `json:"description"` // short description
Type string `json:"type"` // "free" or "freeform"
Price string `json:"price"` // "Free" for the free plan, otherwise the freeform pricing string
AcceptTerms string `json:"accept_terms"` // ToS text shown before changing the plan
}
Plan is a flattened, CLI-friendly view of a self-serve plan template.
type PlanTemplateAttributes ¶ added in v1.11.0
type PlanTemplateAttributes struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"` // e.g. "free" or "freeform"
Freeform string `json:"freeform,omitempty"` // pricing string for paygo plans
Configuration PlanTemplateConfiguration `json:"configuration"`
}
PlanTemplateAttributes contains the actual plan template fields.
type PlanTemplateConfiguration ¶ added in v1.11.0
type PlanTemplateConfiguration struct {
Plan string `json:"plan"`
AcceptTerms string `json:"accept_terms"`
}
PlanTemplateConfiguration holds the plan identifier and the terms text.
type PlanTemplateResource ¶ added in v1.11.0
type PlanTemplateResource struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes PlanTemplateAttributes `json:"attributes"`
}
PlanTemplateResource is a JSON:API resource wrapper for a self-serve plan template.
type PlanTemplatesResponse ¶ added in v1.11.0
type PlanTemplatesResponse struct {
Data []PlanTemplateResource `json:"data"`
}
PlanTemplatesResponse is the JSON:API response from GET /1/plan-templates/self-serve.
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.
type UpdateApplicationRequest ¶ added in v1.11.0
type UpdateApplicationRequest struct {
Name string `json:"name"`
}
UpdateApplicationRequest is the payload for PATCH /1/applications/{id}.