drone/internal/store/database/serviceAccount_sync.go
Johannes Batzill 4668e94027 [Harness] Adding JWT/PAT/SAT Support, Harness Clients, Inline User/ServiceAccount Creation, harness Build flag, ... (#22)
This change adds the initial stepping stones for harness integration:
- Authentication: JWT/PAT/SAT support
- Authorization: ACL integration (acl currently denies requests as gitness hasn't been integrated yet)
- Remote Clients for Token, User, ServiceAccount, ACL
- User Integration: Syncs harness users during authentication if unknown
- SA integration: syncs harness service accounts during authentication if unknown
- Initial harness API: THIS WILL BE CHANGED IN THE FUTURE!
- single harness subpackage (all marked with harness build flag)
- harness & standalone wire + make build commands
2022-09-30 16:22:12 -07:00

80 lines
2.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 database
import (
"context"
"github.com/harness/gitness/internal/store"
"github.com/harness/gitness/internal/store/database/mutex"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
var _ store.ServiceAccountStore = (*ServiceAccountStoreSync)(nil)
// NewServiceAccountStoreSync returns a new ServiceAccountStoreSync.
func NewServiceAccountStoreSync(base *ServiceAccountStore) *ServiceAccountStoreSync {
return &ServiceAccountStoreSync{base}
}
// ServiceAccountStoreSync synchronizes read and write access to the
// service account store. This prevents race conditions when the database
// type is sqlite3.
type ServiceAccountStoreSync struct {
base *ServiceAccountStore
}
// Find finds the service account by id.
func (s *ServiceAccountStoreSync) Find(ctx context.Context, id int64) (*types.ServiceAccount, error) {
mutex.RLock()
defer mutex.RUnlock()
return s.base.Find(ctx, id)
}
// FindUID finds the service account by uid.
func (s *ServiceAccountStoreSync) FindUID(ctx context.Context, uid string) (*types.ServiceAccount, error) {
mutex.RLock()
defer mutex.RUnlock()
return s.base.FindUID(ctx, uid)
}
// Create saves the service account.
func (s *ServiceAccountStoreSync) Create(ctx context.Context, sa *types.ServiceAccount) error {
mutex.RLock()
defer mutex.RUnlock()
return s.base.Create(ctx, sa)
}
// Update updates the service account details.
func (s *ServiceAccountStoreSync) Update(ctx context.Context, sa *types.ServiceAccount) error {
mutex.RLock()
defer mutex.RUnlock()
return s.base.Update(ctx, sa)
}
// Delete deletes the service account.
func (s *ServiceAccountStoreSync) Delete(ctx context.Context, id int64) error {
mutex.RLock()
defer mutex.RUnlock()
return s.base.Delete(ctx, id)
}
// List returns a list of service accounts for a specific parent.
func (s *ServiceAccountStoreSync) List(ctx context.Context, parentType enum.ParentResourceType,
parentID int64) ([]*types.ServiceAccount, error) {
mutex.RLock()
defer mutex.RUnlock()
return s.base.List(ctx, parentType, parentID)
}
// Count returns a count of service accounts for a specific parent.
func (s *ServiceAccountStoreSync) Count(ctx context.Context, parentType enum.ParentResourceType,
parentID int64) (int64, error) {
mutex.RLock()
defer mutex.RUnlock()
return s.base.Count(ctx, parentType, parentID)
}