store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const APIKeyKind = "APIKey"
View Source
const OrgKind = "Organization"

Variables

View Source
var (
	// ErrInvalidKey is returned when the API key is not found in Datastore
	ErrInvalidKey = errors.New("invalid API key")
)

Functions

func GenerateAPIKey

func GenerateAPIKey() (string, error)

GenerateAPIKey generates a random string to be used as API key.

Types

type APIKey

type APIKey struct {
	CreatedAt time.Time `datastore:"created_at"`
	Key       string    `datastore:"key"`
}

APIKey represents a Datastore entity for storing API key metadata.

type DatastoreClient

type DatastoreClient interface {
	Put(ctx context.Context, key *datastore.Key, src interface{}) (*datastore.Key, error)
	Get(ctx context.Context, key *datastore.Key, dst interface{}) error
	GetAll(ctx context.Context, q *datastore.Query, dst interface{}) ([]*datastore.Key, error)
}

DatastoreClient is an interface for interacting with Datastore.

type DatastoreOrgManager

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

DatastoreOrgManager maintains state for managing organizations and API keys in Datastore.

func NewDatastoreManager

func NewDatastoreManager(client DatastoreClient, project, ns string) *DatastoreOrgManager

NewDatastoreManager creates a new DatastoreOrgManager instance.

func (*DatastoreOrgManager) CreateAPIKeyWithValue

func (d *DatastoreOrgManager) CreateAPIKeyWithValue(ctx context.Context, org, value string) (string, error)

CreateAPIKeyWithValue creates a new API key as a child entity of the organization.

func (*DatastoreOrgManager) CreateOrganization

func (d *DatastoreOrgManager) CreateOrganization(ctx context.Context, name, email string) error

CreateOrganization creates a new organization entity in Datastore.

func (*DatastoreOrgManager) GetAPIKeys

func (d *DatastoreOrgManager) GetAPIKeys(ctx context.Context, org string) ([]string, error)

GetAPIKeys retrieves all API keys for an organization

func (*DatastoreOrgManager) GetOrganization

func (d *DatastoreOrgManager) GetOrganization(ctx context.Context, orgName string) (*Organization, error)

GetOrganization retrieves an organization by its name.

func (*DatastoreOrgManager) ValidateKey

func (d *DatastoreOrgManager) ValidateKey(ctx context.Context, key string) (string, error)

ValidateKey checks if the API key exists and returns the associated organization name.

type Organization

type Organization struct {
	Name                  string    `datastore:"name"`
	Email                 string    `datastore:"email"`
	CreatedAt             time.Time `datastore:"created_at"`
	ProbabilityMultiplier *float64  `datastore:"probability_multiplier"`
}

Organization represents a Datastore entity for storing organization metadata.

Jump to

Keyboard shortcuts

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