Skip to content

Commit

Permalink
fix check ca cert
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Apr 22, 2020
1 parent 5d4f7ea commit cf0cf48
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions pkg/keystone/models/servicecertificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ func (man *SServiceCertificateManager) ValidateCreateData(ctx context.Context, u
}
data = v.UpdateCertKeyInfo(ctx, data)

// validate ca cert key
v = validators.NewCertKeyValidator("ca_certificate", "ca_private_key")
if err := v.Validate(data); err != nil {
return nil, err
if caCert, _ := data.GetString("ca_certificate"); len(caCert) > 0 {
vc := validators.NewCertificateValidator("ca_certificate")
if err := vc.Validate(data); err != nil {
return nil, err
}
}
if caPkey, _ := data.GetString("ca_private_key"); len(caPkey) > 0 {
vp := validators.NewPrivateKeyValidator("ca_private_key")
if err := vp.Validate(data); err != nil {
return nil, err
}
}

input := apis.StandaloneResourceCreateInput{}
Expand All @@ -76,10 +83,17 @@ func (cert *SServiceCertificate) ValidateUpdateData(
}
data = v.UpdateCertKeyInfo(ctx, data)

// validate ca cert key
v = validators.NewCertKeyValidator("ca_certificate", "ca_private_key")
if err := v.Validate(data); err != nil {
return nil, err
if caCert, _ := data.GetString("ca_certificate"); len(caCert) > 0 {
vc := validators.NewCertificateValidator("ca_certificate")
if err := vc.Validate(data); err != nil {
return nil, err
}
}
if caPkey, _ := data.GetString("ca_private_key"); len(caPkey) > 0 {
vp := validators.NewPrivateKeyValidator("ca_private_key")
if err := vp.Validate(data); err != nil {
return nil, err
}
}

updateData := jsonutils.NewDict()
Expand Down

0 comments on commit cf0cf48

Please sign in to comment.