Skip to content

Commit

Permalink
run all builtins as plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Becca Petrin committed Oct 23, 2018
1 parent becd10f commit 97c24d7
Show file tree
Hide file tree
Showing 87 changed files with 1,174 additions and 890 deletions.
3 changes: 0 additions & 3 deletions api/sys_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ type EnableAuthOptions struct {
Description string `json:"description"`
Config AuthConfigInput `json:"config"`
Local bool `json:"local"`
PluginName string `json:"plugin_name,omitempty"`
SealWrap bool `json:"seal_wrap" mapstructure:"seal_wrap"`
Options map[string]string `json:"options" mapstructure:"options"`
}

type AuthConfigInput struct {
DefaultLeaseTTL string `json:"default_lease_ttl" mapstructure:"default_lease_ttl"`
MaxLeaseTTL string `json:"max_lease_ttl" mapstructure:"max_lease_ttl"`
PluginName string `json:"plugin_name,omitempty" mapstructure:"plugin_name"`
AuditNonHMACRequestKeys []string `json:"audit_non_hmac_request_keys,omitempty" mapstructure:"audit_non_hmac_request_keys"`
AuditNonHMACResponseKeys []string `json:"audit_non_hmac_response_keys,omitempty" mapstructure:"audit_non_hmac_response_keys"`
ListingVisibility string `json:"listing_visibility,omitempty" mapstructure:"listing_visibility"`
Expand All @@ -110,7 +108,6 @@ type AuthMount struct {
type AuthConfigOutput struct {
DefaultLeaseTTL int `json:"default_lease_ttl" mapstructure:"default_lease_ttl"`
MaxLeaseTTL int `json:"max_lease_ttl" mapstructure:"max_lease_ttl"`
PluginName string `json:"plugin_name,omitempty" mapstructure:"plugin_name"`
AuditNonHMACRequestKeys []string `json:"audit_non_hmac_request_keys,omitempty" mapstructure:"audit_non_hmac_request_keys"`
AuditNonHMACResponseKeys []string `json:"audit_non_hmac_response_keys,omitempty" mapstructure:"audit_non_hmac_response_keys"`
ListingVisibility string `json:"listing_visibility,omitempty" mapstructure:"listing_visibility"`
Expand Down
3 changes: 0 additions & 3 deletions api/sys_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ type MountInput struct {
Config MountConfigInput `json:"config"`
Options map[string]string `json:"options"`
Local bool `json:"local"`
PluginName string `json:"plugin_name,omitempty"`
SealWrap bool `json:"seal_wrap" mapstructure:"seal_wrap"`
}

Expand All @@ -144,7 +143,6 @@ type MountConfigInput struct {
Description *string `json:"description,omitempty" mapstructure:"description"`
MaxLeaseTTL string `json:"max_lease_ttl" mapstructure:"max_lease_ttl"`
ForceNoCache bool `json:"force_no_cache" mapstructure:"force_no_cache"`
PluginName string `json:"plugin_name,omitempty" mapstructure:"plugin_name"`
AuditNonHMACRequestKeys []string `json:"audit_non_hmac_request_keys,omitempty" mapstructure:"audit_non_hmac_request_keys"`
AuditNonHMACResponseKeys []string `json:"audit_non_hmac_response_keys,omitempty" mapstructure:"audit_non_hmac_response_keys"`
ListingVisibility string `json:"listing_visibility,omitempty" mapstructure:"listing_visibility"`
Expand All @@ -165,7 +163,6 @@ type MountConfigOutput struct {
DefaultLeaseTTL int `json:"default_lease_ttl" mapstructure:"default_lease_ttl"`
MaxLeaseTTL int `json:"max_lease_ttl" mapstructure:"max_lease_ttl"`
ForceNoCache bool `json:"force_no_cache" mapstructure:"force_no_cache"`
PluginName string `json:"plugin_name,omitempty" mapstructure:"plugin_name"`
AuditNonHMACRequestKeys []string `json:"audit_non_hmac_request_keys,omitempty" mapstructure:"audit_non_hmac_request_keys"`
AuditNonHMACResponseKeys []string `json:"audit_non_hmac_response_keys,omitempty" mapstructure:"audit_non_hmac_response_keys"`
ListingVisibility string `json:"listing_visibility,omitempty" mapstructure:"listing_visibility"`
Expand Down
24 changes: 19 additions & 5 deletions api/sys_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/vault/helper/consts"
)

// ListPluginsInput is used as input to the ListPlugins function.
type ListPluginsInput struct{}
type ListPluginsInput struct {
// Type of the plugin. Required.
Type consts.PluginType `json:"type"`
}

// ListPluginsResponse is the response from the ListPlugins call.
type ListPluginsResponse struct {
Expand All @@ -18,7 +23,7 @@ type ListPluginsResponse struct {
// ListPlugins lists all plugins in the catalog and returns their names as a
// list of strings.
func (c *Sys) ListPlugins(i *ListPluginsInput) (*ListPluginsResponse, error) {
path := "/v1/sys/plugins/catalog"
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s", i.Type)
req := c.c.NewRequest("LIST", path)

ctx, cancelFunc := context.WithCancel(context.Background())
Expand All @@ -44,6 +49,9 @@ func (c *Sys) ListPlugins(i *ListPluginsInput) (*ListPluginsResponse, error) {
// GetPluginInput is used as input to the GetPlugin function.
type GetPluginInput struct {
Name string `json:"-"`

// Type of the plugin. Required.
Type consts.PluginType `json:"type"`
}

// GetPluginResponse is the response from the GetPlugin call.
Expand All @@ -56,7 +64,7 @@ type GetPluginResponse struct {
}

func (c *Sys) GetPlugin(i *GetPluginInput) (*GetPluginResponse, error) {
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s", i.Name)
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s/%s", i.Type, i.Name)
req := c.c.NewRequest(http.MethodGet, path)

ctx, cancelFunc := context.WithCancel(context.Background())
Expand All @@ -82,6 +90,9 @@ type RegisterPluginInput struct {
// Name is the name of the plugin. Required.
Name string `json:"-"`

// Type of the plugin. Required.
Type consts.PluginType `json:"type"`

// Args is the list of args to spawn the process with.
Args []string `json:"args,omitempty"`

Expand All @@ -94,7 +105,7 @@ type RegisterPluginInput struct {

// RegisterPlugin registers the plugin with the given information.
func (c *Sys) RegisterPlugin(i *RegisterPluginInput) error {
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s", i.Name)
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s/%s", i.Type, i.Name)
req := c.c.NewRequest(http.MethodPut, path)
if err := req.SetJSONBody(i); err != nil {
return err
Expand All @@ -113,12 +124,15 @@ func (c *Sys) RegisterPlugin(i *RegisterPluginInput) error {
type DeregisterPluginInput struct {
// Name is the name of the plugin. Required.
Name string `json:"-"`

// Type of the plugin. Required.
Type consts.PluginType `json:"type"`
}

// DeregisterPlugin removes the plugin with the given name from the plugin
// catalog.
func (c *Sys) DeregisterPlugin(i *DeregisterPluginInput) error {
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s", i.Name)
path := fmt.Sprintf("/v1/sys/plugins/catalog/%s/%s", i.Type, i.Name)
req := c.c.NewRequest(http.MethodDelete, path)

ctx, cancelFunc := context.WithCancel(context.Background())
Expand Down
56 changes: 33 additions & 23 deletions builtin/credential/app-id/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBackend_basic(t *testing.T) {
return b, nil
}
logicaltest.Test(t, logicaltest.TestCase{
Factory: factory,
CredentialFactory: factory,
Steps: []logicaltest.TestStep{
testAccStepMapAppId(t),
testAccStepMapUserId(t),
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestBackend_basic(t *testing.T) {

func TestBackend_cidr(t *testing.T) {
logicaltest.Test(t, logicaltest.TestCase{
Factory: Factory,
CredentialFactory: Factory,
Steps: []logicaltest.TestStep{
testAccStepMapAppIdDisplayName(t),
testAccStepMapUserIdCidr(t, "192.168.1.0/16"),
Expand All @@ -78,7 +78,7 @@ func TestBackend_cidr(t *testing.T) {

func TestBackend_displayName(t *testing.T) {
logicaltest.Test(t, logicaltest.TestCase{
Factory: Factory,
CredentialFactory: Factory,
Steps: []logicaltest.TestStep{
testAccStepMapAppIdDisplayName(t),
testAccStepMapUserId(t),
Expand All @@ -93,8 +93,9 @@ func TestBackend_displayName(t *testing.T) {

func testAccStepMapAppId(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "map/app-id/foo",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "map/app-id/foo",
Data: map[string]interface{}{
"value": "foo,bar",
},
Expand All @@ -103,8 +104,9 @@ func testAccStepMapAppId(t *testing.T) logicaltest.TestStep {

func testAccStepMapAppIdDisplayName(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "map/app-id/foo",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "map/app-id/foo",
Data: map[string]interface{}{
"display_name": "tubbin",
"value": "foo,bar",
Expand All @@ -114,8 +116,9 @@ func testAccStepMapAppIdDisplayName(t *testing.T) logicaltest.TestStep {

func testAccStepMapUserId(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "map/user-id/42",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "map/user-id/42",
Data: map[string]interface{}{
"value": "foo",
},
Expand All @@ -124,15 +127,17 @@ func testAccStepMapUserId(t *testing.T) logicaltest.TestStep {

func testAccStepDeleteUserId(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.DeleteOperation,
Path: "map/user-id/42",
IsAuthBackendRequest: true,
Operation: logical.DeleteOperation,
Path: "map/user-id/42",
}
}

func testAccStepMapUserIdCidr(t *testing.T, cidr string) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "map/user-id/42",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "map/user-id/42",
Data: map[string]interface{}{
"value": "foo",
"cidr_block": cidr,
Expand All @@ -148,8 +153,9 @@ func testAccLogin(t *testing.T, display string) logicaltest.TestStep {
return nil
}
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "login",
Data: map[string]interface{}{
"app_id": "foo",
"user_id": "42",
Expand All @@ -172,8 +178,9 @@ func testAccLoginAppIDInPath(t *testing.T, display string) logicaltest.TestStep
return nil
}
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login/foo",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "login/foo",
Data: map[string]interface{}{
"user_id": "42",
},
Expand All @@ -194,8 +201,9 @@ func testAccLoginCidr(t *testing.T, ip string, err bool) logicaltest.TestStep {
}

return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "login",
Data: map[string]interface{}{
"app_id": "foo",
"user_id": "42",
Expand All @@ -210,8 +218,9 @@ func testAccLoginCidr(t *testing.T, ip string, err bool) logicaltest.TestStep {

func testAccLoginInvalid(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "login",
Data: map[string]interface{}{
"app_id": "foo",
"user_id": "48",
Expand All @@ -225,8 +234,9 @@ func testAccLoginInvalid(t *testing.T) logicaltest.TestStep {

func testAccLoginDeleted(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login",
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "login",
Data: map[string]interface{}{
"app_id": "foo",
"user_id": "42",
Expand Down
File renamed without changes.
36 changes: 20 additions & 16 deletions builtin/credential/aws/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,40 +476,44 @@ func TestBackend_ConfigClient(t *testing.T) {
}

stepCreate := logicaltest.TestStep{
Operation: logical.CreateOperation,
Path: "config/client",
Data: data,
IsAuthBackendRequest: true,
Operation: logical.CreateOperation,
Path: "config/client",
Data: data,
}

stepUpdate := logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data,
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data,
}

data3 := map[string]interface{}{"access_key": "",
"secret_key": "mCtSM8ZUEQ3mOFVZYPBQkf2sO6F/W7a5TVzrl3Oj",
}
stepInvalidAccessKey := logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data3,
ErrorOk: true,
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data3,
ErrorOk: true,
}

data4 := map[string]interface{}{"access_key": "accesskey",
"secret_key": "",
}
stepInvalidSecretKey := logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data4,
ErrorOk: true,
IsAuthBackendRequest: true,
Operation: logical.UpdateOperation,
Path: "config/client",
Data: data4,
ErrorOk: true,
}

logicaltest.Test(t, logicaltest.TestCase{
AcceptanceTest: false,
Backend: b,
AcceptanceTest: false,
CredentialBackend: b,
Steps: []logicaltest.TestStep{
stepCreate,
stepInvalidAccessKey,
Expand Down
Loading

0 comments on commit 97c24d7

Please sign in to comment.