Changes CSR util signername to use if statements rather than switch

Signed-off-by: joshvanl <vleeuwenjoshua@gmail.com>
This commit is contained in:
joshvanl 2021-05-28 10:34:43 +01:00
parent acc5431f1b
commit 36bd7a459c
2 changed files with 16 additions and 18 deletions

View File

@ -637,7 +637,7 @@ func TestCA_Sign(t *testing.T) {
// [1]: https://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
//
// So instead of using a truncation or rounding in order to
// check the time, we use a delta of 1 second. One entire
// check the time, we use a delta of 2 seconds. One entire
// second is totally overkill since, as detailed above, the
// delay is probably less than a microsecond. But that will
// do for now!
@ -648,7 +648,7 @@ func TestCA_Sign(t *testing.T) {
// https://github.com/jetstack/cert-manager/issues/3738
expectNotAfter := time.Now().UTC().Add(30 * time.Minute)
deltaSec := math.Abs(expectNotAfter.Sub(got.NotAfter).Seconds())
assert.LessOrEqualf(t, deltaSec, 1., "expected a time delta lower than 1 second. Time expected='%s', got='%s'", expectNotAfter.String(), got.NotAfter.String())
assert.LessOrEqualf(t, deltaSec, 2., "expected a time delta lower than 2 second. Time expected='%s', got='%s'", expectNotAfter.String(), got.NotAfter.String())
},
},
"when the CertificateSigningRequest has the isCA field set, it should appear on the signed ca": {

View File

@ -40,32 +40,30 @@ func SignerIssuerRefFromSignerName(name string) (SignerIssuerRef, bool) {
return SignerIssuerRef{}, false
}
switch len(signerNameSplit) {
case 1:
if len(signerNameSplit) == 1 {
return SignerIssuerRef{
Namespace: "",
Name: signerNameSplit[0],
Type: signerTypeSplit[0],
Group: signerTypeSplit[1],
}, true
}
default:
// ClusterIssuers do not have Namespaces
if signerTypeSplit[0] == "clusterissuers" {
return SignerIssuerRef{
Namespace: "",
Name: strings.Join(signerNameSplit[0:], "."),
Type: signerTypeSplit[0],
Group: signerTypeSplit[1],
}, true
}
// Non Cluster Scoped issuers always have Namespaces
// ClusterIssuers do not have Namespaces
if signerTypeSplit[0] == "clusterissuers" {
return SignerIssuerRef{
Namespace: signerNameSplit[0],
Name: strings.Join(signerNameSplit[1:], "."),
Namespace: "",
Name: strings.Join(signerNameSplit[0:], "."),
Type: signerTypeSplit[0],
Group: signerTypeSplit[1],
}, true
}
// Non Cluster Scoped issuers always have Namespaces
return SignerIssuerRef{
Namespace: signerNameSplit[0],
Name: strings.Join(signerNameSplit[1:], "."),
Type: signerTypeSplit[0],
Group: signerTypeSplit[1],
}, true
}