Skip to content

Commit

Permalink
Add keyvault auth (#1749)
Browse files Browse the repository at this point in the history
* Add keyvault auth

* Add licnese
  • Loading branch information
mcardosos authored May 1, 2018
1 parent bae6462 commit bba5a45
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
13 changes: 10 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

[[constraint]]
name = "github.com/Azure/go-autorest"
version = "10.7.0"
version = "10.8.0"

[[constraint]]
branch = "master"
Expand Down
51 changes: 51 additions & 0 deletions services/keyvault/auth/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package auth

// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.

import (
"os"
"strings"

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
)

// NewAuthorizerFromEnvironment creates a keyvault dataplane Authorizer configured from environment variables in the order:
// 1. Client credentials
// 2. Client certificate
// 3. Username password
// 4. MSI
func NewAuthorizerFromEnvironment() (autorest.Authorizer, error) {
envName := os.Getenv("AZURE_ENVIRONMENT")
var env azure.Environment
var err error

if envName == "" {
env = azure.PublicCloud
} else {
env, err = azure.EnvironmentFromName(envName)
if err != nil {
return nil, err
}
}

resource := os.Getenv("AZURE_KEYVAULT_RESOURCE")
if resource == "" {
resource = strings.TrimSuffix(env.KeyVaultEndpoint, "/")
}

return auth.NewAuthorizerFromEnvironmentWithResource(resource)
}

0 comments on commit bba5a45

Please sign in to comment.