зеркало из https://github.com/Azure/ARO-RP.git
cleanups to do with service duplication
This commit is contained in:
Родитель
c179469454
Коммит
8265d59a1b
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/mimo/actuator"
|
||||
"github.com/Azure/ARO-RP/pkg/mimo/tasks"
|
||||
"github.com/Azure/ARO-RP/pkg/proxy"
|
||||
"github.com/Azure/ARO-RP/pkg/util/service"
|
||||
"github.com/Azure/ARO-RP/pkg/util/encryption"
|
||||
)
|
||||
|
||||
func mimoActuator(ctx context.Context, log *logrus.Entry) error {
|
||||
|
@ -49,12 +49,17 @@ func mimoActuator(ctx context.Context, log *logrus.Entry) error {
|
|||
}
|
||||
go g.Run()
|
||||
|
||||
dbc, err := service.NewDatabase(ctx, _env, log, m, true)
|
||||
aead, err := encryption.NewAEADWithCore(ctx, _env, env.EncryptionSecretV2Name, env.EncryptionSecretName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbName, err := service.DBName(_env.IsLocalDevelopmentMode())
|
||||
dbc, err := database.NewDatabaseClientFromEnv(ctx, _env, log, m, aead)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbName, err := env.DBName(_env)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package service
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
const (
|
||||
DatabaseName = "DATABASE_NAME"
|
||||
DatabaseAccountName = "DATABASE_ACCOUNT_NAME"
|
||||
KeyVaultPrefix = "KEYVAULT_PREFIX"
|
||||
)
|
|
@ -1,83 +0,0 @@
|
|||
package service
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/database"
|
||||
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/metrics"
|
||||
"github.com/Azure/ARO-RP/pkg/util/encryption"
|
||||
"github.com/Azure/ARO-RP/pkg/util/keyvault"
|
||||
)
|
||||
|
||||
// NewDatabase creates a CosmosDB database client from the environment configuration.
|
||||
func NewDatabase(ctx context.Context, _env env.Core, log *logrus.Entry, m metrics.Emitter, withAEAD bool) (cosmosdb.DatabaseClient, error) {
|
||||
var aead encryption.AEAD
|
||||
|
||||
msiToken, err := _env.NewMSITokenCredential()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if withAEAD {
|
||||
msiKVAuthorizer, err := _env.NewMSIAuthorizer(_env.Environment().KeyVaultScope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keyVaultPrefix := os.Getenv(KeyVaultPrefix)
|
||||
// TODO: should not be using the service keyvault here
|
||||
serviceKeyvaultURI := keyvault.URI(_env, env.ServiceKeyvaultSuffix, keyVaultPrefix)
|
||||
serviceKeyvault := keyvault.NewManager(msiKVAuthorizer, serviceKeyvaultURI)
|
||||
|
||||
aead, err = encryption.NewMulti(
|
||||
ctx,
|
||||
serviceKeyvault,
|
||||
env.EncryptionSecretV2Name,
|
||||
env.EncryptionSecretName,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
dbAccountName := os.Getenv(DatabaseAccountName)
|
||||
scope := []string{
|
||||
fmt.Sprintf("https://%s.%s", dbAccountName, _env.Environment().CosmosDBDNSSuffixScope),
|
||||
}
|
||||
|
||||
logrusEntry := log.WithField("component", "database")
|
||||
|
||||
dbAuthorizer, err := database.NewTokenAuthorizer(
|
||||
ctx,
|
||||
logrusEntry,
|
||||
msiToken,
|
||||
dbAccountName,
|
||||
scope,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbc, err := database.NewDatabaseClient(
|
||||
logrusEntry,
|
||||
_env,
|
||||
dbAuthorizer,
|
||||
m,
|
||||
aead,
|
||||
dbAccountName,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dbc, nil
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package service
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
)
|
||||
|
||||
func DBName(isLocalDevelopmentMode bool) (string, error) {
|
||||
if !isLocalDevelopmentMode {
|
||||
return "ARO", nil
|
||||
}
|
||||
|
||||
if err := env.ValidateVars(DatabaseName); err != nil {
|
||||
return "", fmt.Errorf("%v (development mode)", err.Error())
|
||||
}
|
||||
|
||||
return os.Getenv(DatabaseName), nil
|
||||
}
|
Загрузка…
Ссылка в новой задаче