drone/internal/store/store.go
Johannes Batzill 3ba0f75c8d Introduce UIDs for Space / Repo / Tokens, Add Custom Harness Validation, ... (#57)
This change adds the following:
- Space UID + Custom harness validation (accountId for top level space, harness identifier for child spaces)
- Repo UID + Custom harness validation (harness identifier)
- Store Unique casing of space / repo path and add Path.ValueUnique (with Unique index) to allow for application layer controlling the case sensitivity (case insensitive standalone vs partially case sensitive harness)
- Token UID (unique index over ownertype + ownerID + tokenUID)
- Add DisplayName for principals (replaces Name to avoid confustion)
- Store Unique casing of principal UID and add Principal.ValueUnique (with unique index) to allow for application layer, per principal type control of case sensitivity (required in embedded mode)
- Generate serviceAccount UID (+Email) Randomly (sa-{space|repo}-{ID}-{random}) - Allows to have a unique UID across all principals while reducing likelyhood of overlaps with users + avoid overlap across spaces / repos.
- Sync casing of space names (accountId orgId projectId) when creating spaces on the fly (to ensure case sensitivity of - harness code) or use the existing space to update casing.
- Update serviceaccount client to match updated NG Manager API
- in embedded mode create spaces for harness resources owning the service account
2022-11-06 23:14:47 -08:00

201 lines
6.9 KiB
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
// Package store defines the data storage interfaces.
package store
import (
"context"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
type (
// UserStore defines the user data storage.
UserStore interface {
// Find finds the user by id.
Find(ctx context.Context, id int64) (*types.User, error)
// FindUID finds the user by uid.
FindUID(ctx context.Context, uid string) (*types.User, error)
// FindEmail finds the user by email.
FindEmail(ctx context.Context, email string) (*types.User, error)
// Create saves the user details.
Create(ctx context.Context, user *types.User) error
// Update updates the user details.
Update(ctx context.Context, user *types.User) error
// Delete deletes the user.
Delete(ctx context.Context, id int64) error
// List returns a list of users.
List(ctx context.Context, params *types.UserFilter) ([]*types.User, error)
// Count returns a count of users.
Count(ctx context.Context) (int64, error)
}
// ServiceAccountStore defines the service account data storage.
ServiceAccountStore interface {
// Find finds the service account by id.
Find(ctx context.Context, id int64) (*types.ServiceAccount, error)
// FindUID finds the service account by uid.
FindUID(ctx context.Context, uid string) (*types.ServiceAccount, error)
// Create saves the service account.
Create(ctx context.Context, sa *types.ServiceAccount) error
// Update updates the service account details.
Update(ctx context.Context, sa *types.ServiceAccount) error
// Delete deletes the service account.
Delete(ctx context.Context, id int64) error
// List returns a list of service accounts for a specific parent.
List(ctx context.Context, parentType enum.ParentResourceType, parentID int64) ([]*types.ServiceAccount, error)
// Count returns a count of service accounts for a specific parent.
Count(ctx context.Context, parentType enum.ParentResourceType, parentID int64) (int64, error)
}
// ServiceStore defines the service data storage.
ServiceStore interface {
// Find finds the service by id.
Find(ctx context.Context, id int64) (*types.Service, error)
// FindUID finds the service by uid.
FindUID(ctx context.Context, uid string) (*types.Service, error)
// Create saves the service.
Create(ctx context.Context, sa *types.Service) error
// Update updates the service details.
Update(ctx context.Context, sa *types.Service) error
// Delete deletes the service.
Delete(ctx context.Context, id int64) error
// List returns a list of all services.
List(ctx context.Context) ([]*types.Service, error)
// Count returns a count of all services.
Count(ctx context.Context) (int64, error)
}
// SpaceStore defines the space data storage.
SpaceStore interface {
// Find the space by id.
Find(ctx context.Context, id int64) (*types.Space, error)
// FindByPath the space by its path.
FindByPath(ctx context.Context, path string) (*types.Space, error)
// Create creates a new space
Create(ctx context.Context, space *types.Space) error
// Move moves an existing space.
Move(ctx context.Context, principalID int64, id int64, newParentID int64, newName string,
keepAsAlias bool) (*types.Space, error)
// Update updates the space details.
Update(ctx context.Context, space *types.Space) error
// Delete deletes the space.
Delete(ctx context.Context, id int64) error
// Count the child spaces of a space.
Count(ctx context.Context, id int64, opts *types.SpaceFilter) (int64, error)
// List returns a list of child spaces in a space.
List(ctx context.Context, id int64, opts *types.SpaceFilter) ([]*types.Space, error)
// CountPaths returns a count of all paths of a space.
CountPaths(ctx context.Context, id int64, opts *types.PathFilter) (int64, error)
// ListPaths returns a list of all paths of a space.
ListPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error)
// CreatePath create an alias for a space
CreatePath(ctx context.Context, id int64, params *types.PathParams) (*types.Path, error)
// DeletePath delete an alias of a space
DeletePath(ctx context.Context, id int64, pathID int64) error
}
// RepoStore defines the repository data storage.
RepoStore interface {
// Find the repo by id.
Find(ctx context.Context, id int64) (*types.Repository, error)
// FindByPath the repo by path.
FindByPath(ctx context.Context, path string) (*types.Repository, error)
// Create a new repo
Create(ctx context.Context, repo *types.Repository) error
// Move moves an existing repo.
Move(ctx context.Context, principalID int64, repoID int64, newParentID int64, newName string,
keepAsAlias bool) (*types.Repository, error)
// Update the repo details.
Update(ctx context.Context, repo *types.Repository) error
// Delete the repo.
Delete(ctx context.Context, id int64) error
// Count of repos in a space.
Count(ctx context.Context, parentID int64, opts *types.RepoFilter) (int64, error)
// List returns a list of repos in a space.
List(ctx context.Context, parentID int64, opts *types.RepoFilter) ([]*types.Repository, error)
// CountPaths returns a count of all paths of a repo.
CountPaths(ctx context.Context, id int64, opts *types.PathFilter) (int64, error)
// ListPaths returns a list of all paths of a repo.
ListPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error)
// CreatePath an alias for a repo
CreatePath(ctx context.Context, repoID int64, params *types.PathParams) (*types.Path, error)
// DeletePath delete an alias of a repo
DeletePath(ctx context.Context, repoID int64, pathID int64) error
}
// TokenStore defines the token data storage.
TokenStore interface {
// Find finds the token by id
Find(ctx context.Context, id int64) (*types.Token, error)
// Find finds the token by principalId and tokenUID
FindByUID(ctx context.Context, principalID int64, tokenUID string) (*types.Token, error)
// Create saves the token details.
Create(ctx context.Context, token *types.Token) error
// Delete deletes the token with the given id.
Delete(ctx context.Context, id int64) error
// DeleteForPrincipal deletes all tokens for a specific principal
DeleteForPrincipal(ctx context.Context, principalID int64) error
// List returns a list of tokens of a specific type for a specific principal.
List(ctx context.Context, principalID int64, tokenType enum.TokenType) ([]*types.Token, error)
// Count returns a count of tokens of a specifc type for a specific principal.
Count(ctx context.Context, principalID int64, tokenType enum.TokenType) (int64, error)
}
// SystemStore defines internal system metadata storage.
SystemStore interface {
// Config returns the system configuration.
Config(ctx context.Context) *types.Config
}
)