Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional info for secret drivers #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion secrets/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ const (
// Request is the plugin secret request
type Request struct {
SecretName string `json:",omitempty"` // SecretName is the name of the secret to request from the plugin
SecretLabels map[string]string `json:",omitempty"` // SecretLabels capture environment names and other metadata pertaining to the secret
ServiceHostname string `json:",omitempty"` // ServiceHostname is the hostname of the service, can be used for x509 certificate
ServiceName string `json:",omitempty"` // ServiceName is the name of the service that requested the secret
ServiceLabels map[string]string `json:",omitempty"` // ServiceLabels capture environment names and other metadata
ServiceID string `json:",omitempty"` // ServiceID is the name of the service that requested the secret
ServiceLabels map[string]string `json:",omitempty"` // ServiceLabels capture environment names and other metadata pertaining to the service
TaskID string `json:",omitempty"` // TaskID is the ID of the task that the secret is assigned to
TaskName string `json:",omitempty"` // TaskName is the name of the task that the secret is assigned to
TaskImage string `json:",omitempty"` // TaskName is the image of the task that the secret is assigned to
ServiceEndpointSpec *EndpointSpec `json:",omitempty"` // ServiceEndpointSpec holds the specification for endpoints
}

Expand Down
13 changes: 13 additions & 0 deletions secrets/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func TestHandler(t *testing.T) {
if resp.Err == "" {
t.Fatalf("expected missing secret")
}
resp, err = pluginRequest(client, getPath, Request{SecretName: "another-secret", SecretLabels: map[string]string{"prefix": "p-"}})
if err != nil {
t.Fatal(err)
}
if resp.Err != "" {
t.Fatalf("error while getting secret: %v", resp.Err)
}
if !bytes.EqualFold(append([]byte("p-"), secret...), resp.Value) {
t.Fatalf("expecting secret value %s, got %s", secret, resp.Value)
}
}

func pluginRequest(client *http.Client, method string, req Request) (*Response, error) {
Expand Down Expand Up @@ -74,5 +84,8 @@ func (p *testPlugin) Get(req Request) Response {
if req.SecretName == "" {
return Response{Err: "missing secret name"}
}
if prefix, exists := req.SecretLabels["prefix"]; exists {
return Response{Value: append([]byte(prefix), secret...)}
}
return Response{Value: secret}
}