diff --git a/authority/admin/db.go b/authority/admin/db.go index 6e4e7c49..bf34a3c2 100644 --- a/authority/admin/db.go +++ b/authority/admin/db.go @@ -71,52 +71,6 @@ type DB interface { DeleteAdmin(ctx context.Context, id string) error } -type NoDB struct{} - -func NewNoDB() *NoDB { - return &NoDB{} -} - -func (n *NoDB) CreateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error { - return nil -} - -func (n *NoDB) GetProvisioner(ctx context.Context, id string) (*linkedca.Provisioner, error) { - return nil, nil -} - -func (n *NoDB) GetProvisioners(ctx context.Context) ([]*linkedca.Provisioner, error) { - return nil, nil -} - -func (n *NoDB) UpdateProvisioner(ctx context.Context, prov *linkedca.Provisioner) error { - return nil -} - -func (n *NoDB) DeleteProvisioner(ctx context.Context, id string) error { - return nil -} - -func (n *NoDB) CreateAdmin(ctx context.Context, admin *linkedca.Admin) error { - return nil -} - -func (n *NoDB) GetAdmin(ctx context.Context, id string) (*linkedca.Admin, error) { - return nil, nil -} - -func (n *NoDB) GetAdmins(ctx context.Context) ([]*linkedca.Admin, error) { - return nil, nil -} - -func (n *NoDB) UpdateAdmin(ctx context.Context, prov *linkedca.Admin) error { - return nil -} - -func (n *NoDB) DeleteAdmin(ctx context.Context, id string) error { - return nil -} - // MockDB is an implementation of the DB interface that should only be used as // a mock in tests. type MockDB struct { diff --git a/authority/options.go b/authority/options.go index b583bb89..755e0fbc 100644 --- a/authority/options.go +++ b/authority/options.go @@ -266,6 +266,14 @@ func WithAdminDB(d admin.DB) Option { } } +// WithProvisioners is an option to set the provisioner collection. +func WithProvisioners(ps *provisioner.Collection) Option { + return func(a *Authority) error { + a.provisioners = ps + return nil + } +} + // WithLinkedCAToken is an option to set the authentication token used to enable // linked ca. func WithLinkedCAToken(token string) Option { diff --git a/ca/adminClient.go b/ca/adminClient.go index e898a898..90b0ab1d 100644 --- a/ca/adminClient.go +++ b/ca/adminClient.go @@ -369,12 +369,12 @@ func (c *AdminClient) GetProvisioner(opts ...ProvisionerOption) (*linkedca.Provi } var u *url.URL switch { - case len(o.ID) > 0: + case o.ID != "": u = c.endpoint.ResolveReference(&url.URL{ Path: "/admin/provisioners/id", RawQuery: o.rawQuery(), }) - case len(o.Name) > 0: + case o.Name != "": u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)}) default: return nil, errors.New("must set either name or id in method options") @@ -478,12 +478,12 @@ func (c *AdminClient) RemoveProvisioner(opts ...ProvisionerOption) error { } switch { - case len(o.ID) > 0: + case o.ID != "": u = c.endpoint.ResolveReference(&url.URL{ Path: path.Join(adminURLPrefix, "provisioners/id"), RawQuery: o.rawQuery(), }) - case len(o.Name) > 0: + case o.Name != "": u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)}) default: return errors.New("must set either name or id in method options") diff --git a/ca/client.go b/ca/client.go index 3871c749..44961357 100644 --- a/ca/client.go +++ b/ca/client.go @@ -435,6 +435,7 @@ type ProvisionerOptions struct { Name string } +// Apply caches provisioner options on a struct for later use. func (o *ProvisionerOptions) Apply(opts []ProvisionerOption) (err error) { for _, fn := range opts { if err = fn(o); err != nil { @@ -446,16 +447,16 @@ func (o *ProvisionerOptions) Apply(opts []ProvisionerOption) (err error) { func (o *ProvisionerOptions) rawQuery() string { v := url.Values{} - if len(o.Cursor) > 0 { + if o.Cursor != "" { v.Set("cursor", o.Cursor) } if o.Limit > 0 { v.Set("limit", strconv.Itoa(o.Limit)) } - if len(o.ID) > 0 { + if o.ID != "" { v.Set("id", o.ID) } - if len(o.Name) > 0 { + if o.Name != "" { v.Set("name", o.Name) } return v.Encode()