-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
144 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package database | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"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" | ||
) | ||
|
||
// NewDatabaseClient creates a CosmosDB database client from the environment configuration. | ||
func NewDatabaseClientFromEnv(ctx context.Context, _env env.Core, log *logrus.Entry, m metrics.Emitter, aead encryption.AEAD) (cosmosdb.DatabaseClient, error) { | ||
dbAccountName, err := env.DBAccountName() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
msiToken, err := _env.NewMSITokenCredential() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
scope := []string{ | ||
fmt.Sprintf("https://%s.%s", dbAccountName, _env.Environment().CosmosDBDNSSuffixScope), | ||
} | ||
|
||
logrusEntry := log.WithField("component", "database") | ||
|
||
dbAuthorizer, err := NewTokenAuthorizer( | ||
ctx, logrusEntry, msiToken, dbAccountName, scope, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dbc, err := NewDatabaseClient( | ||
logrusEntry, _env, dbAuthorizer, m, aead, dbAccountName, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return dbc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package env | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const ( | ||
EnvDatabaseName = "DATABASE_NAME" | ||
EnvDatabaseAccountName = "DATABASE_ACCOUNT_NAME" | ||
) | ||
|
||
// Fetch the database account name from the environment. | ||
func DBAccountName() (string, error) { | ||
if err := ValidateVars(EnvDatabaseAccountName); err != nil { | ||
return "", err | ||
} | ||
|
||
return os.Getenv(EnvDatabaseAccountName), nil | ||
} | ||
|
||
func DBName(c Core) (string, error) { | ||
if !c.IsLocalDevelopmentMode() { | ||
return "ARO", nil | ||
} | ||
|
||
if err := ValidateVars(EnvDatabaseName); err != nil { | ||
return "", fmt.Errorf("%v (development mode)", err.Error()) | ||
} | ||
|
||
return os.Getenv(EnvDatabaseName), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package encryption | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/Azure/ARO-RP/pkg/env" | ||
"github.com/Azure/ARO-RP/pkg/util/keyvault" | ||
) | ||
|
||
const ( | ||
KeyVaultPrefix = "KEYVAULT_PREFIX" | ||
) | ||
|
||
// NewAEADWithCore creates an AEAD encryption manager with resources available | ||
// from the Core env object. | ||
func NewAEADWithCore(ctx context.Context, _env env.Core, encryptionSecretV2Name string, encryptionSecretName string) (AEAD, error) { | ||
msiKVAuthorizer, err := _env.NewMSIAuthorizer(_env.Environment().KeyVaultScope) | ||
if err != nil { | ||
return nil, fmt.Errorf("MSI KeyVault Authorizer failed with: %s", err.Error()) | ||
} | ||
|
||
keyVaultPrefix := os.Getenv(KeyVaultPrefix) | ||
serviceKeyvaultURI := keyvault.URI(_env, env.ServiceKeyvaultSuffix, keyVaultPrefix) | ||
serviceKeyvault := keyvault.NewManager(msiKVAuthorizer, serviceKeyvaultURI) | ||
|
||
return NewMulti( | ||
ctx, serviceKeyvault, encryptionSecretV2Name, encryptionSecretName, | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.