Skip to content

Commit

Permalink
Enables live-tests on Azure-Pipeline for keyvault (#273)
Browse files Browse the repository at this point in the history
* Update livetest.yml
  • Loading branch information
JerryPei1997 authored Mar 26, 2020
1 parent 13286d0 commit 587488a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .azure-pipelines/livetest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
jobs:
- job:
pool:
vmImage: 'Ubuntu 18.04'
steps:
- template: steps/init_workspace.yml
- template: steps/live_test.yml
2 changes: 1 addition & 1 deletion .azure-pipelines/steps/init_workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ steps:
go version
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.6
golangci-lint --version
displayName: 'Install Dependencies'
displayName: 'Install Dependencies'
16 changes: 16 additions & 0 deletions .azure-pipelines/steps/live_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:
- script: |
go test -count=1 -v ./keyvault/
displayName: 'Live Test'
env:
AZURE_AUTH_LOCATION: $(AZURE_AUTH_LOCATION)
AZURE_BASE_GROUP_NAME: $(AZURE_BASE_GROUP_NAME)
AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
AZURE_TENANT_ID: $(AZURE_TENANT_ID)
AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
AZURE_LOCATION_DEFAULT: $(AZURE_LOCATION_DEFAULT)
AZURE_SAMPLES_KEEP_RESOURCES: $(AZURE_SAMPLES_KEEP_RESOURCES)
AZURE_USE_DEVICEFLOW: $(AZURE_USE_DEVICEFLOW)
9 changes: 2 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ stages:
- stage: LintAndBuild
jobs:
- template: .azure-pipelines/lint_and_build.yml

- stage: LiveTest
condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI'))
jobs:
- job:
steps:
# the live test script steps.
- script: |
echo 'live test'
displayName: 'Live Test'
- template: .azure-pipelines/livetest.yml
40 changes: 10 additions & 30 deletions internal/config/env.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,46 @@
package config

import (
"fmt"
"log"
"os"
"strconv"

"github.com/Azure/go-autorest/autorest/azure"
"github.com/gobuffalo/envy"
)

// ParseEnvironment loads a sibling `.env` file then looks through all environment
// variables to set global configuration.
func ParseEnvironment() error {
if err := envy.Load(); err != nil {
return err
}
azureEnv, _ := azure.EnvironmentFromName("AzurePublicCloud") // shouldn't fail
authorizationServerURL = azureEnv.ActiveDirectoryEndpoint

// AZURE_GROUP_NAME and `config.GroupName()` are deprecated.
// Use AZURE_BASE_GROUP_NAME and `config.GenerateGroupName()` instead.
groupName = envy.Get("AZURE_GROUP_NAME", "azure-go-samples")
baseGroupName = envy.Get("AZURE_BASE_GROUP_NAME", groupName)
groupName = os.Getenv("AZURE_GROUP_NAME")
baseGroupName = os.Getenv("AZURE_BASE_GROUP_NAME")

locationDefault = envy.Get("AZURE_LOCATION_DEFAULT", "westus2")
locationDefault = os.Getenv("AZURE_LOCATION_DEFAULT")

var err error
useDeviceFlow, err = strconv.ParseBool(envy.Get("AZURE_USE_DEVICEFLOW", "0"))
useDeviceFlow, err = strconv.ParseBool(os.Getenv("AZURE_USE_DEVICEFLOW"))
if err != nil {
log.Printf("invalid value specified for AZURE_USE_DEVICEFLOW, disabling\n")
useDeviceFlow = false
}
keepResources, err = strconv.ParseBool(envy.Get("AZURE_SAMPLES_KEEP_RESOURCES", "0"))
keepResources, err = strconv.ParseBool(os.Getenv("AZURE_SAMPLES_KEEP_RESOURCES"))
if err != nil {
log.Printf("invalid value specified for AZURE_SAMPLES_KEEP_RESOURCES, discarding\n")
keepResources = false
}

// these must be provided by environment
// clientID
clientID, err = envy.MustGet("AZURE_CLIENT_ID")
if err != nil {
return fmt.Errorf("expected env vars not provided: %+v", err)
}
clientID = os.Getenv("AZURE_CLIENT_ID")

// clientSecret
clientSecret, err = envy.MustGet("AZURE_CLIENT_SECRET")
if err != nil && !useDeviceFlow { // don't need a secret for device flow
return fmt.Errorf("expected env vars not provided: %+v", err)
}
clientSecret = os.Getenv("AZURE_CLIENT_SECRET")

// tenantID (AAD)
tenantID, err = envy.MustGet("AZURE_TENANT_ID")
if err != nil {
return fmt.Errorf("expected env vars not provided: %+v", err)
}
tenantID = os.Getenv("AZURE_TENANT_ID")

// subscriptionID (ARM)
subscriptionID, err = envy.MustGet("AZURE_SUBSCRIPTION_ID")
if err != nil {
return fmt.Errorf("expected env vars not provided: %+v", err)
}
subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")

return nil
}
2 changes: 2 additions & 0 deletions keyvault/keyvault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func ExampleSetVaultPermissions() {
if err != nil {
util.LogAndPanic(err)
}
util.PrintAndLog("resource group created")

_, err = CreateVault(ctx, kvName)
if err != nil {
Expand All @@ -73,6 +74,7 @@ func ExampleSetVaultPermissions() {
util.PrintAndLog("created key")

// Output:
// resource group created
// vault created
// set vault permissions
// created key
Expand Down

0 comments on commit 587488a

Please sign in to comment.