mirror of
https://github.com/harness/drone.git
synced 2025-05-07 03:19:14 +08:00

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
109 lines
3.2 KiB
Go
109 lines
3.2 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 database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/harness/gitness/internal/store"
|
|
"github.com/harness/gitness/internal/store/database/mutex"
|
|
"github.com/harness/gitness/types"
|
|
)
|
|
|
|
var _ store.SpaceStore = (*SpaceStoreSync)(nil)
|
|
|
|
// NewSpaceStoreSync returns a new SpaceStoreSync.
|
|
func NewSpaceStoreSync(base *SpaceStore) *SpaceStoreSync {
|
|
return &SpaceStoreSync{base}
|
|
}
|
|
|
|
// SpaceStoreSync synchronizes read and write access to the
|
|
// space store. This prevents race conditions when the database
|
|
// type is sqlite3.
|
|
type SpaceStoreSync struct {
|
|
base *SpaceStore
|
|
}
|
|
|
|
// Find the space by id.
|
|
func (s *SpaceStoreSync) Find(ctx context.Context, id int64) (*types.Space, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Find(ctx, id)
|
|
}
|
|
|
|
// FindByPath find the space by path.
|
|
func (s *SpaceStoreSync) FindByPath(ctx context.Context, path string) (*types.Space, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.FindByPath(ctx, path)
|
|
}
|
|
|
|
// Create a new space.
|
|
func (s *SpaceStoreSync) Create(ctx context.Context, space *types.Space) error {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Create(ctx, space)
|
|
}
|
|
|
|
// Move moves an existing space.
|
|
func (s *SpaceStoreSync) Move(ctx context.Context, principalID int64, id int64, newParentID int64, newName string,
|
|
keepAsAlias bool) (*types.Space, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Move(ctx, principalID, id, newParentID, newName, keepAsAlias)
|
|
}
|
|
|
|
// Update the space details.
|
|
func (s *SpaceStoreSync) Update(ctx context.Context, space *types.Space) error {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Update(ctx, space)
|
|
}
|
|
|
|
// Delete the space.
|
|
func (s *SpaceStoreSync) Delete(ctx context.Context, id int64) error {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Delete(ctx, id)
|
|
}
|
|
|
|
// Count the child spaces of a space.
|
|
func (s *SpaceStoreSync) Count(ctx context.Context, id int64, opts *types.SpaceFilter) (int64, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.Count(ctx, id, opts)
|
|
}
|
|
|
|
// List returns a list of spaces under the parent space.
|
|
func (s *SpaceStoreSync) List(ctx context.Context, id int64, opts *types.SpaceFilter) ([]*types.Space, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.List(ctx, id, opts)
|
|
}
|
|
|
|
// CountPaths returns a count of all paths of a space.
|
|
func (s *SpaceStoreSync) CountPaths(ctx context.Context, id int64, opts *types.PathFilter) (int64, error) {
|
|
return s.base.CountPaths(ctx, id, opts)
|
|
}
|
|
|
|
// ListPaths returns a list of all paths of a space.
|
|
func (s *SpaceStoreSync) ListPaths(ctx context.Context, id int64, opts *types.PathFilter) ([]*types.Path, error) {
|
|
return s.base.ListPaths(ctx, id, opts)
|
|
}
|
|
|
|
// CreatePath a path for a space.
|
|
func (s *SpaceStoreSync) CreatePath(ctx context.Context, id int64, params *types.PathParams) (*types.Path, error) {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.CreatePath(ctx, id, params)
|
|
}
|
|
|
|
// DeletePath a path of a space.
|
|
func (s *SpaceStoreSync) DeletePath(ctx context.Context, id int64, pathID int64) error {
|
|
mutex.RLock()
|
|
defer mutex.RUnlock()
|
|
return s.base.DeletePath(ctx, id, pathID)
|
|
}
|