store

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package store defines datastore types and methods for token-exchange.

This package is public because https://github.com/m-lab/autojoin orgadm tool uses the definitions inside this package to interact with datastore.

Index

Constants

View Source
const (
	AutojoinOrgKind    = "Organization"
	AutojoinAPIKeyKind = "APIKey"
)

Constants specific to the autojoin token-exchange.

View Source
const (
	ClientIntegrationAPIKeyPrefix = "mlabk."
	ClientIntegrationIDPrefix     = "cii_"
	ClientIntegrationKeyIDPrefix  = "ki_"
)

Exported constants for API key format prefixes.

Variables

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

Functions

func FormatAPIKey added in v0.3.1

func FormatAPIKey(integrationID, keyID, keySecret string) string

FormatAPIKey formats an API key from its components.

func GenerateAPIKey

func GenerateAPIKey() (string, error)

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

func GenerateKeyID added in v0.3.1

func GenerateKeyID() (string, error)

GenerateKeyID generates a random key ID in the format "ki_" + 16 hex characters.

Types

type AutojoinAPIKey added in v0.3.0

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

AutojoinAPIKey represents a Datastore entity for storing API key metadata.

type AutojoinManager added in v0.3.0

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

AutojoinManager maintains state for managing organizations and API keys in Datastore in the context of the autojoin API.

func NewAutojoinManager added in v0.3.0

func NewAutojoinManager(client DatastoreClient, project, ns string) *AutojoinManager

NewAutojoinManager creates a new *AutojoinManager instance.

func (*AutojoinManager) CreateAPIKeyWithValue added in v0.3.0

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

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

func (*AutojoinManager) CreateOrganization added in v0.3.0

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

CreateOrganization creates a new organization entity in Datastore.

func (*AutojoinManager) GetAPIKeys added in v0.3.0

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

GetAPIKeys retrieves all API keys for an organization

func (*AutojoinManager) GetOrganization added in v0.3.0

func (d *AutojoinManager) GetOrganization(ctx context.Context, orgName string) (*AutojoinOrganization, error)

GetOrganization retrieves an organization by its name.

func (*AutojoinManager) ValidateKey added in v0.3.0

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

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

type AutojoinOrganization added in v0.3.0

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

AutojoinOrganization represents a Datastore entity for storing organization metadata.

type ClientIntegrationManager added in v0.3.0

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

ClientIntegrationManager maintains state for managing client integrations and API keys in datastore.

func NewClientIntegrationManager added in v0.3.0

func NewClientIntegrationManager(client DatastoreClient, project, ns string) *ClientIntegrationManager

NewClientIntegrationManager creates a new *ClientIntegrationManager instance.

func (*ClientIntegrationManager) CreateAPIKey added in v0.3.1

func (m *ClientIntegrationManager) CreateAPIKey(ctx context.Context, integrationID, keyID, description string, tier int) (*CreateAPIKeyResult, error)

CreateAPIKey creates a new API key for an integration in Datastore. If keyID is empty, a random key ID will be generated. The tier parameter specifies the service tier (0 = default). Returns the integration ID, key ID, and the full API key string.

func (*ClientIntegrationManager) CreateIntegration added in v0.3.1

func (m *ClientIntegrationManager) CreateIntegration(ctx context.Context, integrationID, description string) error

CreateIntegration creates a new integration entity in Datastore.

func (*ClientIntegrationManager) ValidateKey added in v0.3.0

func (m *ClientIntegrationManager) ValidateKey(ctx context.Context, apiKey string) (string, string, int, error)

ValidateKey validates an integration API key using SHA-256 hash comparison.

This method is thread safe.

The return value consists of client-integration ID, key ID, tier, and an error.

type CreateAPIKeyResult added in v0.3.1

type CreateAPIKeyResult struct {
	IntegrationID string
	KeyID         string
	APIKey        string
}

CreateAPIKeyResult holds the result of creating an API key.

type DatastoreClient

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

DatastoreClient is an interface for interacting with Datastore.

Jump to

Keyboard shortcuts

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