mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 05:29:51 +00:00
fix: incorrect azure cloud environment
This commit is contained in:
parent
78600079a4
commit
3c91f29a91
@ -1,13 +1,12 @@
|
||||
package azuredns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/providers/dns/azuredns"
|
||||
|
||||
azcommon "github.com/usual2970/certimate/internal/pkg/vendors/azure-sdk/common"
|
||||
)
|
||||
|
||||
type ChallengeProviderConfig struct {
|
||||
@ -29,16 +28,11 @@ func NewChallengeProvider(config *ChallengeProviderConfig) (challenge.Provider,
|
||||
providerConfig.ClientID = config.ClientId
|
||||
providerConfig.ClientSecret = config.ClientSecret
|
||||
if config.CloudName != "" {
|
||||
switch strings.ToLower(config.CloudName) {
|
||||
case "default", "public", "cloud", "azurecloud":
|
||||
providerConfig.Environment = cloud.AzurePublic
|
||||
case "usgovernment", "azureusgovernment":
|
||||
providerConfig.Environment = cloud.AzureGovernment
|
||||
case "china", "chinacloud", "azurechina", "azurechinacloud":
|
||||
providerConfig.Environment = cloud.AzureChina
|
||||
default:
|
||||
return nil, fmt.Errorf("azuredns: unknown environment %s", config.CloudName)
|
||||
env, err := azcommon.GetEnvironmentConfiguration(config.CloudName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
providerConfig.Environment = env
|
||||
}
|
||||
if config.DnsPropagationTimeout != 0 {
|
||||
providerConfig.PropagationTimeout = time.Duration(config.DnsPropagationTimeout) * time.Second
|
||||
|
47
internal/pkg/vendors/azure-sdk/common/config.go
vendored
Normal file
47
internal/pkg/vendors/azure-sdk/common/config.go
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
|
||||
)
|
||||
|
||||
func IsEnvironmentPublic(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "", "default", "public", "azurecloud":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsEnvironmentGovernment(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "usgovernment", "government", "azureusgovernment", "azuregovernment":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsEnvironmentChina(env string) bool {
|
||||
switch strings.ToLower(env) {
|
||||
case "china", "chinacloud", "azurechina", "azurechinacloud":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func GetEnvironmentConfiguration(env string) (cloud.Configuration, error) {
|
||||
if IsEnvironmentPublic(env) {
|
||||
return cloud.AzurePublic, nil
|
||||
} else if IsEnvironmentGovernment(env) {
|
||||
return cloud.AzureGovernment, nil
|
||||
} else if IsEnvironmentChina(env) {
|
||||
return cloud.AzureChina, nil
|
||||
}
|
||||
|
||||
return cloud.Configuration{}, fmt.Errorf("unknown azure cloud environment %s", env)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user