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

Process v1.0.0 requests #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -7,7 +7,6 @@ package plugin
import (
"context"
"errors"
"strings"

"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/secret"
@@ -31,23 +30,14 @@ type plugin struct {
}

func (p *plugin) Find(ctx context.Context, req *secret.Request) (*drone.Secret, error) {
// drone requests the secret name in secret:key format.
// Extract the secret and key from the string.
parts := strings.Split(req.Name, "#")
if len(parts) != 2 {
return nil, errors.New("invalid or missing secret key")
}
path := parts[0]
name := parts[1]

// makes an api call to the kubernetes secrets manager and
// attempts to retrieve the secret at the requested path.
var secret v1.Secret
err := p.client.Get(ctx, p.namespace, path, &secret)
err := p.client.Get(ctx, p.namespace, req.Path, &secret)
if err != nil {
return nil, err
}
data, ok := secret.Data[name]
data, ok := secret.Data[req.Name]
if !ok {
return nil, errors.New("secret not found")
}
@@ -69,7 +59,7 @@ func (p *plugin) Find(ctx context.Context, req *secret.Request) (*drone.Secret,
}

return &drone.Secret{
Name: name,
Name: req.Name,
Data: string(data),
Pull: true, // always true. use X-Drone-Events to prevent pull requests.
Fork: true, // always true. use X-Drone-Events to prevent pull requests.
@@ -33,7 +33,8 @@ func TestPlugin(t *testing.T) {
File("testdata/secret.protobuf")

req := &secret.Request{
Name: "docker#username",
Path: "docker",
Name: "username",
Build: drone.Build{
Event: "push",
},
@@ -79,7 +80,8 @@ func TestPlugin_FilterRepo(t *testing.T) {
File("testdata/secret.protobuf")

req := &secret.Request{
Name: "docker#username",
Path: "docker",
Name: "username",
Build: drone.Build{
Event: "push",
},
@@ -118,7 +120,8 @@ func TestPlugin_FilterEvent(t *testing.T) {
File("testdata/secret.protobuf")

req := &secret.Request{
Name: "docker#username",
Path: "docker",
Name: "username",
Build: drone.Build{
Event: "pull_request",
},
@@ -143,20 +146,6 @@ func TestPlugin_FilterEvent(t *testing.T) {
}
}

func TestPlugin_InvalidName(t *testing.T) {
req := &secret.Request{
Name: "docker",
}
_, err := New(nil, "default").Find(noContext, req)
if err == nil {
t.Errorf("Expect invalid path error")
return
}
if got, want := err.Error(), "invalid or missing secret key"; got != want {
t.Errorf("Want error message %s, got %s", want, got)
}
}

func TestPlugin_NotFound(t *testing.T) {
defer gock.Off()

@@ -171,7 +160,8 @@ func TestPlugin_NotFound(t *testing.T) {
File("testdata/error.protobuf")

req := &secret.Request{
Name: "docker#username",
Path: "docker",
Name: "username",
Build: drone.Build{
Event: "push",
},
@@ -206,7 +196,8 @@ func TestPlugin_InvalidAttribute(t *testing.T) {
File("testdata/secret.protobuf")

req := &secret.Request{
Name: "docker#token",
Path: "docker",
Name: "token",
Build: drone.Build{
Event: "push",
},