theauthapi

package module
v0.0.0-...-a8f2b1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 8 Imported by: 0

README

theauthapi-go-sdk

OpenSource SDK for the Auth API

This package provides the core functionality for interacting with TheAuthAPI.

Usage

Import the package:

import "github.com/seventy6/theauthapi-go-sdk"

Each service file (api_keys.go, projects.go, accounts.go) should implement the specific API endpoints for that service, following the structure you've defined in your client.

Documentation

Overview

theauthapi/client.go

Package theauthapi provides a Go client for accessing the TheAuthAPI.

Usage:

client := theauthapi.NewClient("YOUR_ACCESS_KEY")

// Use the client to make API calls
isValid, err := client.ApiKeys.IsValidKey(ctx, "EXAMPLE_API_KEY")

theauthapi/errors.go

Index

Constants

View Source
const Version = "0.1.2"

Version is the current version of the SDK

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    int
	Message string
	Err     error
}

APIError represents a generic API error

func NewAPIError

func NewAPIError(statusCode int, message string, err error) *APIError

NewAPIError creates a new APIError

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsNotFound

func (e *APIError) IsNotFound() bool

IsNotFound checks if the error is a 404 Not Found error

func (*APIError) IsUnauthorized

func (e *APIError) IsUnauthorized() bool

IsUnauthorized checks if the error is a 401 Unauthorized error

type Account

type Account struct {
	AuthBaseEntity
	ID   string `json:"id"`
	Name string `json:"name"`
}

Account represents an account entity

type AccountsService

type AccountsService struct {
	// contains filtered or unexported fields
}

func (*AccountsService) List

func (s *AccountsService) List(ctx context.Context) error

type ApiKey

type ApiKey struct {
	Key              string                 `json:"key"`
	Name             string                 `json:"name"`
	CustomMetaData   map[string]interface{} `json:"customMetaData"`
	CustomAccountID  string                 `json:"customAccountId"`
	CustomUserID     string                 `json:"customUserId"`
	Env              Environment            `json:"env"`
	CreatedAt        time.Time              `json:"createdAt"`
	UpdatedAt        time.Time              `json:"updatedAt"`
	IsActive         bool                   `json:"isActive"`
	RateLimitConfigs RateLimitConfiguration `json:"rateLimitConfigs"`
	Expiry           time.Time              `json:"expiry"`
}

ApiKey represents an API key and its associated data

type ApiKeyFilter

type ApiKeyFilter struct {
	ProjectID       *string `json:"projectId,omitempty"`
	Name            *string `json:"name,omitempty"`
	CustomAccountID *string `json:"customAccountId,omitempty"`
	CustomUserID    *string `json:"customUserId,omitempty"`
	IsActive        *bool   `json:"isActive,omitempty"`
}

ApiKeyFilter represents filtering options for API keys

type ApiKeyInput

type ApiKeyInput struct {
	Name             string                  `json:"name"`
	ProjectID        *string                 `json:"projectId,omitempty"`
	Key              *string                 `json:"key,omitempty"`
	CustomMetaData   map[string]interface{}  `json:"customMetaData,omitempty"`
	CustomAccountID  *string                 `json:"customAccountId,omitempty"`
	CustomUserID     *string                 `json:"customUserId,omitempty"`
	RateLimitConfigs *RateLimitConfiguration `json:"rateLimitConfigs,omitempty"`
	Expiry           *time.Time              `json:"expiry,omitempty"`
}

ApiKeyInput represents the input for creating a new API key

type ApiKeysService

type ApiKeysService struct {
	// contains filtered or unexported fields
}

func (*ApiKeysService) IsValidKey

func (s *ApiKeysService) IsValidKey(ctx context.Context, key string) (string, error)

type AuthBaseEntity

type AuthBaseEntity struct {
	IsActive          bool              `json:"isActive"`
	CreatedBy         string            `json:"createdBy"`
	CreatedByType     *AuthedEntityType `json:"createdByType,omitempty"`
	CreatedIn         string            `json:"createdIn"`
	LastChangedBy     string            `json:"lastChangedBy"`
	LastChangedByType *AuthedEntityType `json:"lastChangedByType,omitempty"`
	UpdatedAt         time.Time         `json:"updatedAt"`
	CreatedAt         time.Time         `json:"createdAt"`
}

AuthBaseEntity contains common fields for authenticated entities

type AuthedEntityType

type AuthedEntityType string

AuthedEntityType represents the type of authenticated entity

const (
	AuthedEntityTypeUser      AuthedEntityType = "USER"
	AuthedEntityTypeAccessKey AuthedEntityType = "ACCESS_KEY"
)

type Client

type Client struct {
	AccessToken string
	BaseURL     string
	HTTPClient  *http.Client
	ApiKeys     *ApiKeysService
	Projects    *ProjectsService
	Accounts    *AccountsService
}

Client is the main TheAuthAPI client

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new TheAuthAPI client with optional configurations

type ClientOption

type ClientOption func(*Client)

ClientOption allows customizing the client

func WithAccessToken

func WithAccessToken(accessToken string) ClientOption

WithAccessToken sets the access token for the client

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL allows overriding the base API URL (useful for testing)

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient allows providing a custom HTTP client

type CreateProjectInput

type CreateProjectInput struct {
	Name      string      `json:"name"`
	AccountID string      `json:"accountId"`
	Env       Environment `json:"env"`
}

CreateProjectInput represents the input for creating a new project

type Environment

type Environment string

Environment represents the environment type

const (
	EnvironmentLive Environment = "live"
	EnvironmentTest Environment = "test"
)

type Project

type Project struct {
	AuthBaseEntity
	ID        string      `json:"id"`
	Name      string      `json:"name"`
	AccountID string      `json:"accountId"`
	Env       Environment `json:"env"`
}

Project represents a project entity

type ProjectsService

type ProjectsService struct {
	// contains filtered or unexported fields
}

func (*ProjectsService) List

func (s *ProjectsService) List(ctx context.Context) ([]Project, error)

type RateLimitConfiguration

type RateLimitConfiguration struct {
	RateLimit    int `json:"rateLimit"`
	RateLimitTtl int `json:"rateLimitTtl"`
}

RateLimitConfiguration defines rate limiting settings

type Response

type Response struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
}

Common response structure

type UpdateApiKeyInput

type UpdateApiKeyInput struct {
	Name             string                  `json:"name"`
	Key              *string                 `json:"key,omitempty"`
	CustomMetaData   map[string]interface{}  `json:"customMetaData,omitempty"`
	CustomAccountID  *string                 `json:"customAccountId,omitempty"`
	CustomUserID     *string                 `json:"customUserId,omitempty"`
	Expiry           *time.Time              `json:"expiry,omitempty"`
	RateLimitConfigs *RateLimitConfiguration `json:"rateLimitConfigs,omitempty"`
}

UpdateApiKeyInput represents the input for updating an API key

type UpdateProjectInput

type UpdateProjectInput struct {
	Name string `json:"name"`
}

UpdateProjectInput represents the input for updating a project

Directories

Path Synopsis
examples
api_keys command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL