Skip to content

Commit

Permalink
Merge pull request #99 from kichristensen/updateAzureModules
Browse files Browse the repository at this point in the history
Update azure modules
  • Loading branch information
schristoff authored Dec 12, 2024
2 parents 878da86 + f033864 commit e3a68bd
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://help.github.com/en/articles/about-code-owners#codeowners-syntax

* @carolynvs @simongdavies @sgettys @bdegeeter
* @getporter/maintainers
22 changes: 9 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ replace (
require (
get.porter.sh/magefiles v0.6.8
get.porter.sh/porter v1.2.0
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/adal v0.9.24
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.3.0
github.com/carolynvs/magex v0.9.0
github.com/cnabio/cnab-go v0.25.2
github.com/hashicorp/go-hclog v1.6.3
Expand All @@ -29,13 +27,10 @@ require (
)

require (
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.1.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/PuerkitoBio/goquery v1.10.0 // indirect
Expand All @@ -51,7 +46,6 @@ require (
github.com/containerd/stargz-snapshotter/estargz v0.16.1 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20231217050601-ba74d44ecf5f // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v27.3.1+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
Expand All @@ -66,7 +60,7 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-yaml v1.14.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-containerregistry v0.20.2 // indirect
Expand All @@ -82,6 +76,7 @@ require (
github.com/jeremywohl/flatten v1.0.1 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -104,6 +99,7 @@ require (
github.com/osteele/tuesday v1.0.3 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
78 changes: 27 additions & 51 deletions go.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"

"get.porter.sh/magefiles/ci"
"get.porter.sh/magefiles/git"
"get.porter.sh/magefiles/porter"
"get.porter.sh/magefiles/releases"
"get.porter.sh/magefiles/tools"
Expand Down Expand Up @@ -138,3 +139,7 @@ func XBuildAll() {
func Clean() error {
return os.RemoveAll("bin")
}

func SetupDCO() error {
return git.SetupDCO()
}
17 changes: 0 additions & 17 deletions pkg/azure/azureconfig/config.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
package azureconfig

type Config struct {

// EnvConnectionString is the environment variable from which the connection
// string should be loaded.
EnvConnectionString string `json:"env"`

// StorageAccount contains the name of the storage account to be used by the Azure storage plugin, if the azure connection environment variable is not set and this proeprty and StorageAccountResourceGroup are populated and the user is logged in with the Azure CLI
// the Storage Account Key will be looked up at runtime using the logged in users credentials
StorageAccount string `json:"account"`
// StorageAccountResourceGroup contains the name of the resource group containing the storage account to be used by the Azure storage plugin, if the azure connection environment variable is not set and this property and StorageAccount are populated and the user is logged in with the Azure CLI
// the Storage Account Key will be looked up at runtime using the logged in users credentials
StorageAccountResourceGroup string `json:"resource-group"`
// StorageAccountSubscriptionId contains the subscription id of the subscription to be used when looking up the Storage Account Key, if this is not set then the current CLI subscription will be used
StorageAccountSubscriptionId string `json:"subscription-id"`

// If set to true data will be compressed before being written to Table storage.
StorageCompressData bool `json:"compress-data"`

// EnvAzurePrefix is the prefix applied to every azure
// environment variable For example, for a prefix of "DEV_AZURE_", the
// variables would be "DEV_AZURE_TENANT_ID", "DEV_AZURE_CLIENT_ID",
Expand Down
53 changes: 12 additions & 41 deletions pkg/azure/keyvault/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ import (
"strings"

"get.porter.sh/plugin/azure/pkg/azure/azureconfig"
"github.com/Azure/azure-sdk-for-go/services/keyvault/auth"
"github.com/Azure/go-autorest/autorest"
azureauth "github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/hashicorp/go-hclog"
"github.com/pkg/errors"
)

// GetCredentials gets an authorizer for Azure
func GetCredentials(cfg azureconfig.Config, l hclog.Logger) (autorest.Authorizer, error) {
func GetCredentials(cfg azureconfig.Config, l hclog.Logger) (*azidentity.DefaultAzureCredential, error) {

azureAuthEnvVarNames := []string{
azureauth.TenantID,
azureauth.ClientID,
azureauth.ClientSecret,
azureauth.CertificatePath,
azureauth.CertificatePassword,
azureauth.Username,
azureauth.Password,
"AZURE_TENANT_ID",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"AZURE_CERTIFICATE_PATH",
"AZURE_CERTIFICATE_PASSWORD",
"AZURE_USERNAME",
"AZURE_PASSWORD",
}

prefix := cfg.EnvAzurePrefix
Expand All @@ -34,36 +31,10 @@ func GetCredentials(cfg azureconfig.Config, l hclog.Logger) (autorest.Authorizer
}
}

var authorizer autorest.Authorizer
var err error

// Attempt to login with az cli if no vars are set.

if noAzureAuthEnvVarsAreSet(azureAuthEnvVarNames) {
authorizer, err = auth.NewAuthorizerFromCLI()
if err != nil {
return nil, errors.Wrap(err, "Failed to create an azure authorizer from azure cli")
}

return authorizer, nil
}

// NewAuthorizierFromEnvironment attempts to authenticate using credentials, certicates, user name and password and MSI however if we get here MSI login wll be skipped as env vars are set so one of the other methods will be attempted

authorizer, err = auth.NewAuthorizerFromEnvironment()
creds, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, errors.Wrap(err, "Failed to create an azure authorizer from environment")
return nil, err
}

return authorizer, nil
}

func noAzureAuthEnvVarsAreSet(azureAuthEnvVarNames []string) bool {
for _, v := range azureAuthEnvVarNames {
val := os.Getenv(v)
if len(val) > 0 {
return false
}
}
return true
return creds, nil
}
203 changes: 0 additions & 203 deletions pkg/azure/keyvault/credentials_test.go

This file was deleted.

Loading

0 comments on commit e3a68bd

Please sign in to comment.