Explorar o código

Fixes for PR review

max furman %!s(int64=4) %!d(string=hai) anos
pai
achega
bfb406bf70
Modificáronse 4 ficheiros con 16 adicións e 53 borrados
  1. 0 46
      authority/admin/db.go
  2. 8 0
      authority/options.go
  3. 4 4
      ca/adminClient.go
  4. 4 3
      ca/client.go

+ 0 - 46
authority/admin/db.go

@@ -71,52 +71,6 @@ type DB interface {
 	DeleteAdmin(ctx context.Context, id string) error
 	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
 // MockDB is an implementation of the DB interface that should only be used as
 // a mock in tests.
 // a mock in tests.
 type MockDB struct {
 type MockDB struct {

+ 8 - 0
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
 // WithLinkedCAToken is an option to set the authentication token used to enable
 // linked ca.
 // linked ca.
 func WithLinkedCAToken(token string) Option {
 func WithLinkedCAToken(token string) Option {

+ 4 - 4
ca/adminClient.go

@@ -369,12 +369,12 @@ func (c *AdminClient) GetProvisioner(opts ...ProvisionerOption) (*linkedca.Provi
 	}
 	}
 	var u *url.URL
 	var u *url.URL
 	switch {
 	switch {
-	case len(o.ID) > 0:
+	case o.ID != "":
 		u = c.endpoint.ResolveReference(&url.URL{
 		u = c.endpoint.ResolveReference(&url.URL{
 			Path:     "/admin/provisioners/id",
 			Path:     "/admin/provisioners/id",
 			RawQuery: o.rawQuery(),
 			RawQuery: o.rawQuery(),
 		})
 		})
-	case len(o.Name) > 0:
+	case o.Name != "":
 		u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)})
 		u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)})
 	default:
 	default:
 		return nil, errors.New("must set either name or id in method options")
 		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 {
 	switch {
-	case len(o.ID) > 0:
+	case o.ID != "":
 		u = c.endpoint.ResolveReference(&url.URL{
 		u = c.endpoint.ResolveReference(&url.URL{
 			Path:     path.Join(adminURLPrefix, "provisioners/id"),
 			Path:     path.Join(adminURLPrefix, "provisioners/id"),
 			RawQuery: o.rawQuery(),
 			RawQuery: o.rawQuery(),
 		})
 		})
-	case len(o.Name) > 0:
+	case o.Name != "":
 		u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)})
 		u = c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "provisioners", o.Name)})
 	default:
 	default:
 		return errors.New("must set either name or id in method options")
 		return errors.New("must set either name or id in method options")

+ 4 - 3
ca/client.go

@@ -435,6 +435,7 @@ type ProvisionerOptions struct {
 	Name   string
 	Name   string
 }
 }
 
 
+// Apply caches provisioner options on a struct for later use.
 func (o *ProvisionerOptions) Apply(opts []ProvisionerOption) (err error) {
 func (o *ProvisionerOptions) Apply(opts []ProvisionerOption) (err error) {
 	for _, fn := range opts {
 	for _, fn := range opts {
 		if err = fn(o); err != nil {
 		if err = fn(o); err != nil {
@@ -446,16 +447,16 @@ func (o *ProvisionerOptions) Apply(opts []ProvisionerOption) (err error) {
 
 
 func (o *ProvisionerOptions) rawQuery() string {
 func (o *ProvisionerOptions) rawQuery() string {
 	v := url.Values{}
 	v := url.Values{}
-	if len(o.Cursor) > 0 {
+	if o.Cursor != "" {
 		v.Set("cursor", o.Cursor)
 		v.Set("cursor", o.Cursor)
 	}
 	}
 	if o.Limit > 0 {
 	if o.Limit > 0 {
 		v.Set("limit", strconv.Itoa(o.Limit))
 		v.Set("limit", strconv.Itoa(o.Limit))
 	}
 	}
-	if len(o.ID) > 0 {
+	if o.ID != "" {
 		v.Set("id", o.ID)
 		v.Set("id", o.ID)
 	}
 	}
-	if len(o.Name) > 0 {
+	if o.Name != "" {
 		v.Set("name", o.Name)
 		v.Set("name", o.Name)
 	}
 	}
 	return v.Encode()
 	return v.Encode()