add validation to the correct place

Signed-off-by: Tomáš Freund <tomas.freund@datamole.cz>
This commit is contained in:
Tomáš Freund
2021-08-12 13:26:16 +02:00
parent bf0d2d5613
commit e343ff5015
7 changed files with 24 additions and 12 deletions
+2 -2
View File
@@ -500,11 +500,11 @@ type ACMEIssuerDNS01ProviderAzureDNS struct {
// +optional
Environment AzureDNSEnvironment `json:"environment,omitempty"`
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityResourceID)
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityResourceID)
// +optional
ManagedIdentityClientID string `json:"managedIdentityClientID,omitempty"`
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityClientID)
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityClientID)
// +optional
ManagedIdentityResourceID string `json:"managedIdentityResourceID,omitempty"`
}
+2 -2
View File
@@ -497,11 +497,11 @@ type ACMEIssuerDNS01ProviderAzureDNS struct {
// +optional
Environment AzureDNSEnvironment `json:"environment,omitempty"`
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityResourceID)
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityResourceID)
// +optional
ManagedIdentityClientID string `json:"managedIdentityClientID,omitempty"`
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityClientID)
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityClientID)
// +optional
ManagedIdentityResourceID string `json:"managedIdentityResourceID,omitempty"`
}
+2 -2
View File
@@ -497,11 +497,11 @@ type ACMEIssuerDNS01ProviderAzureDNS struct {
// +optional
Environment AzureDNSEnvironment `json:"environment,omitempty"`
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityResourceID)
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityResourceID)
// +optional
ManagedIdentityClientID string `json:"managedIdentityClientID,omitempty"`
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityClientID)
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityClientID)
// +optional
ManagedIdentityResourceID string `json:"managedIdentityResourceID,omitempty"`
}
+2 -2
View File
@@ -496,11 +496,11 @@ type ACMEIssuerDNS01ProviderAzureDNS struct {
// +optional
Environment AzureDNSEnvironment `json:"environment,omitempty"`
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityResourceID)
// clientID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityResourceID)
// +optional
ManagedIdentityClientID string `json:"managedIdentityClientID,omitempty"`
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time with ManagedIdentityClientID)
// resourceID of the MSI that should be used (only relevant when using MSI, can not be used at the same time as ManagedIdentityClientID)
// +optional
ManagedIdentityResourceID string `json:"managedIdentityResourceID,omitempty"`
}
+4
View File
@@ -427,6 +427,10 @@ type ACMEIssuerDNS01ProviderAzureDNS struct {
HostedZoneName string
Environment AzureDNSEnvironment
ManagedIdentityClientID string
ManagedIdentityResourceID string
}
type AzureDNSEnvironment string
@@ -335,6 +335,18 @@ func ValidateACMEChallengeSolverDNS01(p *cmacme.ACMEChallengeSolverDNS01, fldPat
if len(p.AzureDNS.TenantID) == 0 {
el = append(el, field.Required(fldPath.Child("azureDNS", "tenantID"), ""))
}
if len(p.AzureDNS.ManagedIdentityClientID) > 0 {
el = append(el, field.Forbidden(fldPath.Child("azureDNS", "managedIdentityClientID"), "managed identity can not be used at the same time as clientID, tenantID or clientSecret"))
}
if len(p.AzureDNS.ManagedIdentityResourceID) > 0 {
el = append(el, field.Forbidden(fldPath.Child("azureDNS", "managedIdentityResourceID"), "managed identity can not be used at the same time as clientID, tenantID or clientSecret"))
}
} else {
// using managed identity
if len(p.AzureDNS.ManagedIdentityClientID) > 0 && len(p.AzureDNS.ManagedIdentityResourceID) > 0 {
el = append(el, field.Forbidden(fldPath.Child("azureDNS"), "managedIdentityClientID and managedIdentityResourceID connot both be specified"))
}
}
// SubscriptionID must always be defined
if len(p.AzureDNS.SubscriptionID) == 0 {
-4
View File
@@ -49,10 +49,6 @@ func NewDNSProviderCredentials(environment, clientID, clientSecret, subscription
}
}
if managedIdentityClientID != "" && managedIdentityResourceID != "" {
return nil, fmt.Errorf("managedIdentityClientID and managedIdentityResourceID can not be set at the same time")
}
spt, err := getAuthorization(env, clientID, clientSecret, subscriptionID, tenantID, ambient, managedIdentityClientID, managedIdentityResourceID)
if err != nil {
return nil, err