drone/internal/store/store.go
Johannes Batzill 5786ad2409 [Embedded] Harness Router, Inline Space Creation, Bootstrap, Harness/Admin User Setup (#28)
Adds the basic for harness embedded mode:
- Harness dedicated router with custom APIHandler
- Inline Space Creation
- Client for Account/Org/Project
- Bootstrap (Allows for automated creation of admin user and gitness service (used for all platform required ops))
- Inline harness service principal creation
- Ignore flag for ACL.
2022-10-10 21:32:14 -07:00

192 lines
6.5 KiB
Go

// Copyright 2021 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, spaceID 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) (int64, error)
// List returns a list of child spaces in a space.
List(ctx context.Context, id int64, opts *types.SpaceFilter) ([]*types.Space, error)
// ListAllPaths returns a list of all paths of a space.
ListAllPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error)
// CreatePath create an alias for a space
CreatePath(ctx context.Context, spaceID int64, params *types.PathParams) (*types.Path, error)
// DeletePath delete an alias of a space
DeletePath(ctx context.Context, spaceID 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, newSpaceID 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, spaceID int64) (int64, error)
// List returns a list of repos in a space.
List(ctx context.Context, spaceID int64, opts *types.RepoFilter) ([]*types.Repository, error)
// ListAllPaths returns a list of all alias paths of a repo.
ListAllPaths(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)
// 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
// Delete 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
}
)