Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateAPIKey() (string, error)
- type APIKey
- type DatastoreClient
- type DatastoreOrgManager
- func (d *DatastoreOrgManager) CreateAPIKeyWithValue(ctx context.Context, org, value string) (string, error)
- func (d *DatastoreOrgManager) CreateOrganization(ctx context.Context, name, email string) error
- func (d *DatastoreOrgManager) GetAPIKeys(ctx context.Context, org string) ([]string, error)
- func (d *DatastoreOrgManager) GetOrganization(ctx context.Context, orgName string) (*Organization, error)
- func (d *DatastoreOrgManager) ValidateKey(ctx context.Context, key string) (string, error)
- type Organization
Constants ¶
const APIKeyKind = "APIKey"
const OrgKind = "Organization"
Variables ¶
var ( // ErrInvalidKey is returned when the API key is not found in Datastore ErrInvalidKey = errors.New("invalid API key") )
Functions ¶
func GenerateAPIKey ¶
GenerateAPIKey generates a random string to be used as API key.
Types ¶
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 ¶
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 ¶
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.