Fixes for PR review

pull/915/head
max furman 2 years ago
parent 25b8d196d8
commit bfb406bf70

@ -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 {

@ -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 {

@ -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")

@ -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()

Loading…
Cancel
Save