drone/internal/store/store.go
Johannes Batzill 1115a5083b Add Paths support and error improvements (#11)
This change is adding the concept of Paths.
A repository and space always have a Primary Path which always is represents the ancestry to the root space.
All access history / resource visibility / child listings / UI traversal / etc. is done via that path.

Additionally, repos and spaces can have Alias Paths, which as the name states are aliases. via the primary path.
They sole impact is that a space or repo can be reached via different paths from the UI / rest apis / git apis.
This fulfills two major purposes:
- Customers can rename or move projects and spaces without breaking any existing references from CI pipeliens / code bases / local repos / ...
- Customer can create shorter aliases for important repos when in harness embeded mode! (acc/org/proj/repo can be shortened to acc/repo, or acc/repo'

Apart from the path changes, this PR adds:

Improved User facing errors
Improved internal error handling and wrapping
update / rename operation for repo and space
path list / delete / create operation for repo and space
2022-09-08 21:39:15 -07:00

120 lines
3.9 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"
)
type (
// UserStore defines the user data storage.
UserStore interface {
// Find finds the user by id.
Find(ctx context.Context, id int64) (*types.User, error)
// FindEmail finds the user by email.
FindEmail(ctx context.Context, email string) (*types.User, error)
// FindKey finds the user by unique key (email or id).
FindKey(ctx context.Context, key 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, user *types.User) 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)
}
// SpaceStore defines the space data storage.
SpaceStore interface {
// Finds the space by id.
Find(ctx context.Context, id int64) (*types.Space, error)
// Finds the space by its path.
FindByPath(ctx context.Context, path string) (*types.Space, error)
// Creates a new space
Create(ctx context.Context, space *types.Space) error
// Moves an existing space.
Move(ctx context.Context, userId int64, spaceId int64, newParentId int64, newName string, keepAsAlias bool) (*types.Space, error)
// Updates the space details.
Update(ctx context.Context, space *types.Space) error
// 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)
// List returns a list of all paths of a space.
ListAllPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error)
// Create an alias for a space
CreatePath(ctx context.Context, spaceId int64, params *types.PathParams) (*types.Path, error)
// Delete an alias of a space
DeletePath(ctx context.Context, spaceId int64, pathId int64) error
}
// RepoStore defines the repository data storage.
RepoStore interface {
// Finds the repo by id.
Find(ctx context.Context, id int64) (*types.Repository, error)
// Finds the repo by path.
FindByPath(ctx context.Context, path string) (*types.Repository, error)
// Creates a new repo
Create(ctx context.Context, repo *types.Repository) error
// Moves an existing repo.
Move(ctx context.Context, userId int64, repoId int64, newSpaceId int64, newName string, keepAsAlias bool) (*types.Repository, error)
// Updates the repo details.
Update(ctx context.Context, repo *types.Repository) error
// Deletes 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)
// List returns a list of all alias paths of a repo.
ListAllPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error)
// Create an alias for a repo
CreatePath(ctx context.Context, repoId int64, params *types.PathParams) (*types.Path, error)
// Delete an alias of a repo
DeletePath(ctx context.Context, repoId int64, pathId int64) error
}
// SystemStore defines internal system metadata storage.
SystemStore interface {
// Config returns the system configuration.
Config(ctx context.Context) *types.Config
}
)