From a32f86e40dc70832371171fc132901915d5d1091 Mon Sep 17 00:00:00 2001 From: Keepers Date: Mon, 17 Oct 2022 14:47:04 -0600 Subject: [PATCH] migrate naming of azure env vars (#1176) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description migrates the client_id, client_secret, and tenant_id environment variables to versions prepended with azure_*. ⚠️ Your local environment will need to change in the following ways: ⚠️ 1. prepend `AZURE_` to your clientID, clientSecret, and tenantID env vars. 2. update those same env references in any `.corso.env` files used for copying envs to docker containers. 3. in `.corso.toml` (and any variants such as .corso_test.toml), replace `tenantid` with `azure_tenantid`. ## Type of change - [x] :hamster: Trivial/Minor ## Issue(s) * #558 ## Test Plan - [x] :muscle: Manual - [x] :zap: Unit test - [x] :green_heart: E2E --- .github/workflows/ci.yml | 6 +-- .github/workflows/ci_test_cleanup.yml | 6 +-- .github/workflows/load_test.yml | 14 +++---- design/cli.md | 8 ++-- docs/docs/configuration/m365_access.md | 6 +-- docs/docs/developers/testing.md | 6 +-- docs/docs/install.md | 6 +-- src/cli/config/account.go | 17 ++++---- src/cli/config/config.go | 6 +-- src/cli/config/config_test.go | 40 +++++++++---------- src/cli/help/env.go | 4 +- src/cmd/factory/factory.go | 6 +-- src/cmd/purge/purge.go | 4 +- .../exchange/contact_folder_cache_test.go | 1 + .../exchange/event_calendar_cache_test.go | 1 + .../exchange/exchange_service_test.go | 17 ++++---- .../connector/exchange/iterators_test.go | 1 + .../exchange/mail_folder_cache_test.go | 1 + .../connector/exchange/service_functions.go | 10 ++--- .../exchange/service_functions_test.go | 1 + .../connector/exchange/service_iterators.go | 4 +- src/internal/connector/graph_connector.go | 10 ++--- .../graph_connector_disconnected_test.go | 6 +-- .../connector/graph_connector_test.go | 1 + src/internal/connector/onedrive/drive.go | 6 ++- src/internal/connector/onedrive/drive_test.go | 6 +-- src/internal/connector/onedrive/item_test.go | 3 +- src/internal/events/events_test.go | 6 +-- src/internal/tester/account.go | 8 ++-- src/internal/tester/config.go | 4 +- src/internal/tester/integration_runners.go | 28 +++++++------ src/pkg/account/m365.go | 30 +++++++------- src/pkg/account/m365_test.go | 30 +++++++------- src/pkg/credentials/m365.go | 16 ++++---- 34 files changed, 167 insertions(+), 152 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ce623da8..7714e3023 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,12 +135,12 @@ jobs: # run the tests - name: Integration Tests env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_CLIENT_ID: ${{ secrets.CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_TENANT_ID: ${{ secrets.TENANT_ID }} CORSO_CI_TESTS: true CORSO_M356_TEST_USER_ID: ${{ secrets.CORSO_M356_TEST_USER_ID }} CORSO_PASSPHRASE: ${{ secrets.INTEGRATION_TEST_CORSO_PASSPHRASE }} - TENANT_ID: ${{ secrets.TENANT_ID }} run: | set -euo pipefail go test \ diff --git a/.github/workflows/ci_test_cleanup.yml b/.github/workflows/ci_test_cleanup.yml index a8feca884..7886ffbd1 100644 --- a/.github/workflows/ci_test_cleanup.yml +++ b/.github/workflows/ci_test_cleanup.yml @@ -31,11 +31,11 @@ jobs: - name: Purge folders working-directory: ./src env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_CLIENT_ID: ${{ secrets.CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_TENANT_ID: ${{ secrets.TENANT_ID }} CORSO_M356_TEST_USER_ID: ${{ secrets.CORSO_M356_TEST_USER_ID }} DELETE_FOLDER_PREFIX: "Corso_Restore_" - TENANT_ID: ${{ secrets.TENANT_ID }} run: > go run ./cmd/purge/purge.go --user ${{ secrets.CORSO_M356_TEST_USER_ID }} diff --git a/.github/workflows/load_test.yml b/.github/workflows/load_test.yml index 750f20c0e..d9ff4d0bf 100644 --- a/.github/workflows/load_test.yml +++ b/.github/workflows/load_test.yml @@ -48,11 +48,11 @@ jobs: # run the tests - name: Integration Tests env: - CORSO_LOAD_TESTS: true - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_CLIENT_ID: ${{ secrets.CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_TENANT_ID: ${{ secrets.TENANT_ID }} CORSO_PASSPHRASE: ${{ secrets.INTEGRATION_TEST_CORSO_PASSPHRASE }} - TENANT_ID: ${{ secrets.TENANT_ID }} + CORSO_LOAD_TESTS: true run: | set -euo pipefail go test \ @@ -84,10 +84,10 @@ jobs: if: always() working-directory: ./src env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_CLIENT_ID: ${{ secrets.CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + AZURE_TENANT_ID: ${{ secrets.TENANT_ID }} DELETE_FOLDER_PREFIX: "Corso_Restore_" - TENANT_ID: ${{ secrets.TENANT_ID }} run: > go run ./cmd/purge/purge.go --user '*' diff --git a/design/cli.md b/design/cli.md index 98cade417..9d2cc4166 100644 --- a/design/cli.md +++ b/design/cli.md @@ -37,8 +37,8 @@ Standard format: | --- | --- | --- | --- | --- | | repo | * | | | Same as `repo [*] --help`. | | repo | init | {repository} | | Initialize a Corso repository. | -| repo | init | {repository} | —tenant {tenant_id} | Provides the account’s tenant ID. | -| repo | init | {repository} | —client {client_id} | Provides the account’s client ID. | +| repo | init | {repository} | —tenant {azure_tenant_id} | Provides the account’s tenant ID. | +| repo | init | {repository} | —client {azure_client_id} | Provides the account’s client ID. | | repo | connect | {repository} | | Connects to the specified repo. | | repo | configure | {repository} | | Sets mutable config properties to the provided values. | | repo | * | * | —config {cfg_file_path} | Specify a repo configuration file. Values may also be provided via individual flags and env vars. | @@ -68,10 +68,10 @@ Standard format: **First Run** ```bash -$ export O365_SECRET=my_0365_secret +$ export AZURE_CLIENT_SECRET=my_azure_secret $ export AWS_SECRET_ACCESS_KEY=my_s3_secret $ corso repo init s3 --bucket my_s3_bucket --access-key my_s3_key \ - --tenant my_m365_acct --clientid my_m365_client_id + --tenant my_azure_tenant_id --clientid my_azure_client_id $ corso backup express ``` diff --git a/docs/docs/configuration/m365_access.md b/docs/docs/configuration/m365_access.md index 08099ecb0..c955fc226 100644 --- a/docs/docs/configuration/m365_access.md +++ b/docs/docs/configuration/m365_access.md @@ -60,8 +60,8 @@ To extract the tenant and client ID, select Overview from the app management pan environment variables. ```bash -export TENANT_ID= -export CLIENT_ID= +export AZURE_TENANT_ID= +export AZURE_CLIENT_ID= ``` @@ -75,7 +75,7 @@ Click **New Client Secret** and follow the instructions to create a secret. Afte value right away because it won't be available later and export it as an environment variable. ```bash -export CLIENT_SECRET= +export AZURE_CLIENT_SECRET= ``` diff --git a/docs/docs/developers/testing.md b/docs/docs/developers/testing.md index e2e64b44e..7ab0a9c40 100644 --- a/docs/docs/developers/testing.md +++ b/docs/docs/developers/testing.md @@ -33,9 +33,9 @@ > You can find more information on how to get these values in [configuration docs](/configuration/m365_access). ```bash - export TENANT_ID= - export CLIENT_ID= - export CLIENT_SECRET= + export AZURE_CLIENT_ID= + export AZURE_CLIENT_SECRET= + export AZURE_TENANT_ID= ``` ## Running tests diff --git a/docs/docs/install.md b/docs/docs/install.md index 65116e4ea..007223d93 100644 --- a/docs/docs/install.md +++ b/docs/docs/install.md @@ -36,9 +36,9 @@ To create the environment variables file, you can run the following. # create an env vars file $ cat < 0 { - c.ClientID = a.Config[keyM365ClientID] - c.ClientSecret = a.Config[keyM365ClientSecret] - c.TenantID = a.Config[keyM365TenantID] + c.AzureClientID = a.Config[keyAzureClientID] + c.AzureClientSecret = a.Config[keyAzureClientSecret] + c.AzureTenantID = a.Config[keyAzureTenantID] } return c, c.validate() @@ -59,9 +59,9 @@ func (a Account) M365Config() (M365Config, error) { func (c M365Config) validate() error { check := map[string]string{ - credentials.ClientID: c.ClientID, - credentials.ClientSecret: c.ClientSecret, - TenantID: c.TenantID, + credentials.AzureClientID: c.AzureClientID, + credentials.AzureClientSecret: c.AzureClientSecret, + AzureTenantID: c.AzureTenantID, } for k, v := range check { diff --git a/src/pkg/account/m365_test.go b/src/pkg/account/m365_test.go index b9b2c363b..a201496e4 100644 --- a/src/pkg/account/m365_test.go +++ b/src/pkg/account/m365_test.go @@ -21,10 +21,10 @@ func TestM365CfgSuite(t *testing.T) { var goodM365Config = account.M365Config{ M365: credentials.M365{ - ClientID: "cid", - ClientSecret: "cs", + AzureClientID: "cid", + AzureClientSecret: "cs", }, - TenantID: "tid", + AzureTenantID: "tid", } func (suite *M365CfgSuite) TestM365Config_Config() { @@ -36,9 +36,9 @@ func (suite *M365CfgSuite) TestM365Config_Config() { key string expect string }{ - {"m365_clientID", m365.ClientID}, - {"m365_clientSecret", m365.ClientSecret}, - {"m365_tenantID", m365.TenantID}, + {"azure_clientid", m365.AzureClientID}, + {"azure_clientSecret", m365.AzureClientSecret}, + {"azure_tenantid", m365.AzureTenantID}, } for _, test := range table { assert.Equal(suite.T(), test.expect, c[test.key]) @@ -54,18 +54,18 @@ func (suite *M365CfgSuite) TestAccount_M365Config() { out, err := a.M365Config() require.NoError(t, err) - assert.Equal(t, in.ClientID, out.ClientID) - assert.Equal(t, in.ClientSecret, out.ClientSecret) - assert.Equal(t, in.TenantID, out.TenantID) + assert.Equal(t, in.AzureClientID, out.AzureClientID) + assert.Equal(t, in.AzureClientSecret, out.AzureClientSecret) + assert.Equal(t, in.AzureTenantID, out.AzureTenantID) } func makeTestM365Cfg(cid, cs, tid string) account.M365Config { return account.M365Config{ M365: credentials.M365{ - ClientID: cid, - ClientSecret: cs, + AzureClientID: cid, + AzureClientSecret: cs, }, - TenantID: tid, + AzureTenantID: tid, } } @@ -94,19 +94,19 @@ func (suite *M365CfgSuite) TestAccount_M365Config_InvalidCases() { { "missing clientID", func(a account.Account) { - a.Config["m365_clientID"] = "" + a.Config["azure_clientid"] = "" }, }, { "missing client secret", func(a account.Account) { - a.Config["m365_clientSecret"] = "" + a.Config["azure_clientSecret"] = "" }, }, { "missing tenant id", func(a account.Account) { - a.Config["m365_tenantID"] = "" + a.Config["azure_tenantid"] = "" }, }, } diff --git a/src/pkg/credentials/m365.go b/src/pkg/credentials/m365.go index c0652c67b..2d0943aa7 100644 --- a/src/pkg/credentials/m365.go +++ b/src/pkg/credentials/m365.go @@ -8,14 +8,14 @@ import ( // envvar consts const ( - ClientID = "CLIENT_ID" - ClientSecret = "CLIENT_SECRET" + AzureClientID = "AZURE_CLIENT_ID" + AzureClientSecret = "AZURE_CLIENT_SECRET" ) // M365 aggregates m365 credentials from flag and env_var values. type M365 struct { - ClientID string - ClientSecret string + AzureClientID string + AzureClientSecret string } // M365 is a helper for aggregating m365 secrets and credentials. @@ -23,15 +23,15 @@ func GetM365() M365 { // todo (rkeeprs): read from either corso config file or env vars. // https://github.com/alcionai/corso/issues/120 return M365{ - ClientID: os.Getenv(ClientID), - ClientSecret: os.Getenv(ClientSecret), + AzureClientID: os.Getenv(AzureClientID), + AzureClientSecret: os.Getenv(AzureClientSecret), } } func (c M365) Validate() error { check := map[string]string{ - ClientID: c.ClientID, - ClientSecret: c.ClientSecret, + AzureClientID: c.AzureClientID, + AzureClientSecret: c.AzureClientSecret, } for k, v := range check {