2020-09-09 02:26:32 +00:00
|
|
|
package apiv1
|
|
|
|
|
|
|
|
import (
|
2020-09-11 02:09:46 +00:00
|
|
|
"crypto"
|
|
|
|
"crypto/x509"
|
2020-09-09 02:26:32 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Options represents the configuration options used to select and configure the
|
|
|
|
// CertificateAuthorityService (CAS) to use.
|
|
|
|
type Options struct {
|
|
|
|
// The type of the CAS to use.
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
|
|
|
// Path to the credentials file used in CloudCAS
|
|
|
|
CredentialsFile string `json:"credentialsFile"`
|
2020-09-11 02:09:46 +00:00
|
|
|
|
|
|
|
// CertificateAuthority reference. In CloudCAS the format is
|
|
|
|
// `projects/*/locations/*/certificateAuthorities/*`.
|
|
|
|
Certificateauthority string `json:"certificateAuthority"`
|
|
|
|
|
|
|
|
// Issuer and signer are the issuer certificate and signer used in SoftCAS.
|
|
|
|
// They are configured in ca.json crt and key properties.
|
|
|
|
Issuer *x509.Certificate `json:"-"`
|
|
|
|
Signer crypto.Signer `json:"-"`
|
2020-09-09 02:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate checks the fields in Options.
|
|
|
|
func (o *Options) Validate() error {
|
2020-09-11 02:09:46 +00:00
|
|
|
var typ Type
|
2020-09-09 02:26:32 +00:00
|
|
|
if o == nil {
|
2020-09-11 02:09:46 +00:00
|
|
|
typ = Type(SoftCAS)
|
|
|
|
} else {
|
|
|
|
typ = Type(o.Type)
|
2020-09-09 02:26:32 +00:00
|
|
|
}
|
2020-09-11 02:09:46 +00:00
|
|
|
// Check that the type can be loaded.
|
|
|
|
if _, ok := LoadCertificateAuthorityServiceNewFunc(typ); !ok {
|
|
|
|
return errors.Errorf("unsupported cas type %s", typ)
|
2020-09-09 02:26:32 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-10 23:19:18 +00:00
|
|
|
|
|
|
|
// HasType returns if the options have the given type.
|
|
|
|
func (o *Options) HasType(t Type) bool {
|
|
|
|
if o == nil {
|
2020-09-11 02:09:46 +00:00
|
|
|
return t.String() == SoftCAS
|
2020-09-10 23:19:18 +00:00
|
|
|
}
|
|
|
|
return Type(o.Type).String() == t.String()
|
|
|
|
}
|