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
113 lines
2.7 KiB
Go
113 lines
2.7 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/types"
|
|
|
|
"github.com/google/wire"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
const (
|
|
postgres = "postgres"
|
|
)
|
|
|
|
// WireSet provides a wire set for this package.
|
|
var WireSet = wire.NewSet(
|
|
ProvideDatabase,
|
|
ProvideUserStore,
|
|
ProvideServiceAccountStore,
|
|
ProvideServiceStore,
|
|
ProvideSpaceStore,
|
|
ProvideRepoStore,
|
|
ProvideTokenStore,
|
|
)
|
|
|
|
// ProvideDatabase provides a database connection.
|
|
func ProvideDatabase(ctx context.Context, config *types.Config) (*sqlx.DB, error) {
|
|
return Connect(
|
|
ctx,
|
|
config.Database.Driver,
|
|
config.Database.Datasource,
|
|
)
|
|
}
|
|
|
|
// ProvideUserStore provides a user store.
|
|
func ProvideUserStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTransformation) store.UserStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewUserStore(db, uidTransformation)
|
|
default:
|
|
return NewUserStoreSync(
|
|
NewUserStore(db, uidTransformation),
|
|
)
|
|
}
|
|
}
|
|
|
|
// ProvideServiceAccountStore provides a service account store.
|
|
func ProvideServiceAccountStore(db *sqlx.DB,
|
|
uidTransformation store.PrincipalUIDTransformation) store.ServiceAccountStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewServiceAccountStore(db, uidTransformation)
|
|
default:
|
|
return NewServiceAccountStoreSync(
|
|
NewServiceAccountStore(db, uidTransformation),
|
|
)
|
|
}
|
|
}
|
|
|
|
// ProvideServiceStore provides a service store.
|
|
func ProvideServiceStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTransformation) store.ServiceStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewServiceStore(db, uidTransformation)
|
|
default:
|
|
return NewServiceStoreSync(
|
|
NewServiceStore(db, uidTransformation),
|
|
)
|
|
}
|
|
}
|
|
|
|
// ProvideSpaceStore provides a space store.
|
|
func ProvideSpaceStore(db *sqlx.DB, pathTransformation store.PathTransformation) store.SpaceStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewSpaceStore(db, pathTransformation)
|
|
default:
|
|
return NewSpaceStoreSync(
|
|
NewSpaceStore(db, pathTransformation),
|
|
)
|
|
}
|
|
}
|
|
|
|
// ProvideRepoStore provides a repo store.
|
|
func ProvideRepoStore(db *sqlx.DB, pathTransformation store.PathTransformation) store.RepoStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewRepoStore(db, pathTransformation)
|
|
default:
|
|
return NewRepoStoreSync(
|
|
NewRepoStore(db, pathTransformation),
|
|
)
|
|
}
|
|
}
|
|
|
|
// ProvideTokenStore provides a token store.
|
|
func ProvideTokenStore(db *sqlx.DB) store.TokenStore {
|
|
switch db.DriverName() {
|
|
case postgres:
|
|
return NewTokenStore(db)
|
|
default:
|
|
return NewTokenStoreSync(
|
|
NewTokenStore(db),
|
|
)
|
|
}
|
|
}
|