internalise uuid into database clients

This commit is contained in:
Jim Minter 2020-09-25 16:24:53 -05:00
Родитель 590f04c9f4
Коммит 8cf6c9dbe7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0730CBDA10D1A2D3
10 изменённых файлов: 46 добавлений и 58 удалений

Просмотреть файл

@ -9,7 +9,6 @@ import (
"os"
"github.com/Azure/go-autorest/tracing"
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"k8s.io/client-go/tools/metrics"
@ -25,9 +24,6 @@ import (
)
func monitor(ctx context.Context, log *logrus.Entry) error {
uuid := uuid.NewV4().String()
log.Printf("uuid %s", uuid)
_env, err := env.NewCore(ctx, log)
if err != nil {
return err
@ -64,7 +60,7 @@ func monitor(ctx context.Context, log *logrus.Entry) error {
return err
}
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, m, cipher, uuid)
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, m, cipher)
if err != nil {
return err
}

Просмотреть файл

@ -11,7 +11,6 @@ import (
"syscall"
"github.com/Azure/go-autorest/tracing"
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"k8s.io/client-go/tools/metrics"
@ -33,9 +32,6 @@ import (
)
func rp(ctx context.Context, log *logrus.Entry) error {
uuid := uuid.NewV4().String()
log.Printf("uuid %s", uuid)
_env, err := env.NewEnv(ctx, log)
if err != nil {
return err
@ -82,7 +78,7 @@ func rp(ctx context.Context, log *logrus.Entry) error {
return err
}
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, m, cipher, uuid)
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, m, cipher)
if err != nil {
return err
}

Просмотреть файл

@ -34,7 +34,7 @@ func run(ctx context.Context, log *logrus.Entry) error {
return err
}
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, &noop.Noop{}, cipher, "")
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), _env, &noop.Noop{}, cipher)
if err != nil {
return err
}

Просмотреть файл

@ -15,8 +15,7 @@ import (
)
type asyncOperations struct {
c cosmosdb.AsyncOperationDocumentClient
uuid string
c cosmosdb.AsyncOperationDocumentClient
}
// AsyncOperations is the database interface for AsyncOperationDocuments
@ -27,7 +26,7 @@ type AsyncOperations interface {
}
// NewAsyncOperations returns a new AsyncOperations
func NewAsyncOperations(ctx context.Context, deploymentMode deployment.Mode, uuid string, dbc cosmosdb.DatabaseClient) (AsyncOperations, error) {
func NewAsyncOperations(ctx context.Context, deploymentMode deployment.Mode, dbc cosmosdb.DatabaseClient) (AsyncOperations, error) {
dbid, err := databaseName(deploymentMode)
if err != nil {
return nil, err
@ -35,13 +34,12 @@ func NewAsyncOperations(ctx context.Context, deploymentMode deployment.Mode, uui
collc := cosmosdb.NewCollectionClient(dbc, dbid)
client := cosmosdb.NewAsyncOperationDocumentClient(collc, collAsyncOperations)
return NewAsyncOperationsWithProvidedClient(uuid, client), nil
return NewAsyncOperationsWithProvidedClient(client), nil
}
func NewAsyncOperationsWithProvidedClient(uuid string, client cosmosdb.AsyncOperationDocumentClient) AsyncOperations {
func NewAsyncOperationsWithProvidedClient(client cosmosdb.AsyncOperationDocumentClient) AsyncOperations {
return &asyncOperations{
c: client,
uuid: uuid,
c: client,
}
}

Просмотреть файл

@ -15,8 +15,7 @@ import (
)
type billing struct {
c cosmosdb.BillingDocumentClient
uuid string
c cosmosdb.BillingDocumentClient
}
// Billing is the database interface for BillingDocuments
@ -31,7 +30,7 @@ type Billing interface {
}
// NewBilling returns a new Billing
func NewBilling(ctx context.Context, deploymentMode deployment.Mode, uuid string, dbc cosmosdb.DatabaseClient) (Billing, error) {
func NewBilling(ctx context.Context, deploymentMode deployment.Mode, dbc cosmosdb.DatabaseClient) (Billing, error) {
dbid, err := databaseName(deploymentMode)
if err != nil {
return nil, err
@ -83,13 +82,12 @@ func NewBilling(ctx context.Context, deploymentMode deployment.Mode, uuid string
}
documentClient := cosmosdb.NewBillingDocumentClient(collc, collBilling)
return NewBillingWithProvidedClient(uuid, documentClient), nil
return NewBillingWithProvidedClient(documentClient), nil
}
func NewBillingWithProvidedClient(uuid string, client cosmosdb.BillingDocumentClient) Billing {
func NewBillingWithProvidedClient(client cosmosdb.BillingDocumentClient) Billing {
return &billing{
c: client,
uuid: uuid,
c: client,
}
}

Просмотреть файл

@ -64,7 +64,7 @@ func NewDatabaseClient(ctx context.Context, log *logrus.Entry, env env.Core, m m
}
// NewDatabase returns a new Database
func NewDatabase(ctx context.Context, log *logrus.Entry, env env.Core, m metrics.Interface, cipher encryption.Cipher, uuid string) (db *Database, err error) {
func NewDatabase(ctx context.Context, log *logrus.Entry, env env.Core, m metrics.Interface, cipher encryption.Cipher) (db *Database, err error) {
dbc, err := NewDatabaseClient(ctx, log, env, m, cipher)
if err != nil {
return nil, err
@ -72,27 +72,27 @@ func NewDatabase(ctx context.Context, log *logrus.Entry, env env.Core, m metrics
db = &Database{}
db.AsyncOperations, err = NewAsyncOperations(ctx, env.DeploymentMode(), uuid, dbc)
db.AsyncOperations, err = NewAsyncOperations(ctx, env.DeploymentMode(), dbc)
if err != nil {
return nil, err
}
db.Billing, err = NewBilling(ctx, env.DeploymentMode(), uuid, dbc)
db.Billing, err = NewBilling(ctx, env.DeploymentMode(), dbc)
if err != nil {
return nil, err
}
db.Monitors, err = NewMonitors(ctx, env.DeploymentMode(), uuid, dbc)
db.Monitors, err = NewMonitors(ctx, env.DeploymentMode(), dbc)
if err != nil {
return nil, err
}
db.OpenShiftClusters, err = NewOpenShiftClusters(ctx, env.DeploymentMode(), uuid, dbc)
db.OpenShiftClusters, err = NewOpenShiftClusters(ctx, env.DeploymentMode(), dbc)
if err != nil {
return nil, err
}
db.Subscriptions, err = NewSubscriptions(ctx, env.DeploymentMode(), uuid, dbc)
db.Subscriptions, err = NewSubscriptions(ctx, env.DeploymentMode(), dbc)
if err != nil {
return nil, err
}

Просмотреть файл

@ -9,6 +9,8 @@ import (
"net/http"
"strings"
uuid "github.com/satori/go.uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/deployment"
@ -30,7 +32,7 @@ type Monitors interface {
}
// NewMonitors returns a new Monitors
func NewMonitors(ctx context.Context, deploymentMode deployment.Mode, uuid string, dbc cosmosdb.DatabaseClient) (Monitors, error) {
func NewMonitors(ctx context.Context, deploymentMode deployment.Mode, dbc cosmosdb.DatabaseClient) (Monitors, error) {
dbid, err := databaseName(deploymentMode)
if err != nil {
return nil, err
@ -63,7 +65,7 @@ func NewMonitors(ctx context.Context, deploymentMode deployment.Mode, uuid strin
return &monitors{
c: cosmosdb.NewMonitorDocumentClient(collc, collMonitors),
uuid: uuid,
uuid: uuid.NewV4().String(),
}, nil
}

Просмотреть файл

@ -10,6 +10,7 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
uuid "github.com/satori/go.uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
@ -51,7 +52,7 @@ type OpenShiftClusters interface {
}
// NewOpenShiftClusters returns a new OpenShiftClusters
func NewOpenShiftClusters(ctx context.Context, deploymentMode deployment.Mode, uuid string, dbc cosmosdb.DatabaseClient) (OpenShiftClusters, error) {
func NewOpenShiftClusters(ctx context.Context, deploymentMode deployment.Mode, dbc cosmosdb.DatabaseClient) (OpenShiftClusters, error) {
dbid, err := databaseName(deploymentMode)
if err != nil {
return nil, err
@ -83,14 +84,14 @@ func NewOpenShiftClusters(ctx context.Context, deploymentMode deployment.Mode, u
}
documentClient := cosmosdb.NewOpenShiftClusterDocumentClient(collc, collOpenShiftClusters)
return NewOpenShiftClustersWithProvidedClient(uuid, documentClient, collc), nil
return NewOpenShiftClustersWithProvidedClient(documentClient, collc), nil
}
func NewOpenShiftClustersWithProvidedClient(uuid string, client cosmosdb.OpenShiftClusterDocumentClient, collectionClient cosmosdb.CollectionClient) OpenShiftClusters {
func NewOpenShiftClustersWithProvidedClient(client cosmosdb.OpenShiftClusterDocumentClient, collectionClient cosmosdb.CollectionClient) OpenShiftClusters {
return &openShiftClusters{
c: client,
collc: collectionClient,
uuid: uuid,
uuid: uuid.NewV4().String(),
}
}

Просмотреть файл

@ -9,6 +9,8 @@ import (
"net/http"
"strings"
uuid "github.com/satori/go.uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/deployment"
@ -33,7 +35,7 @@ type Subscriptions interface {
}
// NewSubscriptions returns a new Subscriptions
func NewSubscriptions(ctx context.Context, deploymentMode deployment.Mode, uuid string, dbc cosmosdb.DatabaseClient) (Subscriptions, error) {
func NewSubscriptions(ctx context.Context, deploymentMode deployment.Mode, dbc cosmosdb.DatabaseClient) (Subscriptions, error) {
dbid, err := databaseName(deploymentMode)
if err != nil {
return nil, err
@ -77,13 +79,13 @@ func NewSubscriptions(ctx context.Context, deploymentMode deployment.Mode, uuid
}
documentClient := cosmosdb.NewSubscriptionDocumentClient(collc, collSubscriptions)
return NewSubscriptionsWithProvidedClient(uuid, documentClient), nil
return NewSubscriptionsWithProvidedClient(documentClient), nil
}
func NewSubscriptionsWithProvidedClient(uuid string, client cosmosdb.SubscriptionDocumentClient) Subscriptions {
func NewSubscriptionsWithProvidedClient(client cosmosdb.SubscriptionDocumentClient) Subscriptions {
return &subscriptions{
c: client,
uuid: uuid,
uuid: uuid.NewV4().String(),
}
}

Просмотреть файл

@ -4,7 +4,6 @@ package database
// Licensed under the Apache License 2.0.
import (
uuid "github.com/satori/go.uuid"
"github.com/ugorji/go/codec"
"github.com/Azure/ARO-RP/pkg/database"
@ -13,34 +12,30 @@ import (
var jsonHandle *codec.JsonHandle = database.NewJSONHandle(&fakeCipher{})
func NewFakeOpenShiftClusters() (db database.OpenShiftClusters, client *cosmosdb.FakeOpenShiftClusterDocumentClient, _uuid string) {
_uuid = uuid.NewV4().String()
func NewFakeOpenShiftClusters() (db database.OpenShiftClusters, client *cosmosdb.FakeOpenShiftClusterDocumentClient) {
coll := &fakeCollectionClient{}
client = cosmosdb.NewFakeOpenShiftClusterDocumentClient(jsonHandle)
injectOpenShiftClusters(client)
db = database.NewOpenShiftClustersWithProvidedClient(_uuid, client, coll)
return db, client, _uuid
db = database.NewOpenShiftClustersWithProvidedClient(client, coll)
return db, client
}
func NewFakeSubscriptions() (db database.Subscriptions, client *cosmosdb.FakeSubscriptionDocumentClient, _uuid string) {
_uuid = uuid.NewV4().String()
func NewFakeSubscriptions() (db database.Subscriptions, client *cosmosdb.FakeSubscriptionDocumentClient) {
client = cosmosdb.NewFakeSubscriptionDocumentClient(jsonHandle)
injectSubscriptions(client)
db = database.NewSubscriptionsWithProvidedClient(_uuid, client)
return db, client, _uuid
db = database.NewSubscriptionsWithProvidedClient(client)
return db, client
}
func NewFakeBilling() (db database.Billing, client *cosmosdb.FakeBillingDocumentClient, _uuid string) {
_uuid = uuid.NewV4().String()
func NewFakeBilling() (db database.Billing, client *cosmosdb.FakeBillingDocumentClient) {
client = cosmosdb.NewFakeBillingDocumentClient(jsonHandle)
injectBilling(client)
db = database.NewBillingWithProvidedClient(_uuid, client)
return db, client, _uuid
db = database.NewBillingWithProvidedClient(client)
return db, client
}
func NewFakeAsyncOperations() (db database.AsyncOperations, client *cosmosdb.FakeAsyncOperationDocumentClient, _uuid string) {
_uuid = uuid.NewV4().String()
func NewFakeAsyncOperations() (db database.AsyncOperations, client *cosmosdb.FakeAsyncOperationDocumentClient) {
client = cosmosdb.NewFakeAsyncOperationDocumentClient(jsonHandle)
db = database.NewAsyncOperationsWithProvidedClient(_uuid, client)
return db, client, _uuid
db = database.NewAsyncOperationsWithProvidedClient(client)
return db, client
}