mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-22 01:50:40 +00:00
rollback to previous secret format
This commit is contained in:
parent
6d6664de36
commit
7ac6807806
@ -10,7 +10,6 @@ steps:
|
||||
- name: test
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- go vet ./...
|
||||
- go test ./...
|
||||
|
||||
...
|
||||
|
8
LICENSE
8
LICENSE
@ -2,13 +2,13 @@ Copyright 2019 Drone.IO, Inc.
|
||||
|
||||
Source code in this repository is variously licensed under the
|
||||
Apache License Version 2.0, an Apache compatible license, or the
|
||||
Drone Non-Commercial License. Source code in a given file is
|
||||
licensed under the Drone Non-Commercial License unless otherwise
|
||||
noted at the beginning of the file.
|
||||
Drone Community License. Source code in a given file is licensed
|
||||
under the Drone Community License unless otherwise noted at the
|
||||
beginning of the file.
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Drone Non-Commercial License
|
||||
Drone Community License
|
||||
|
||||
Contributor: Drone.IO, Inc.
|
||||
|
||||
|
@ -86,9 +86,9 @@ func createStep(spec *engine.Spec, src *yaml.Container) *engine.Step {
|
||||
// appends the environment variables to the
|
||||
// container definition.
|
||||
for key, value := range src.Environment {
|
||||
if value.Secret.Name != "" {
|
||||
if value.Secret != "" {
|
||||
sec := &engine.SecretVar{
|
||||
Name: value.Secret.Name,
|
||||
Name: value.Secret,
|
||||
Env: key,
|
||||
}
|
||||
dst.Secrets = append(dst.Secrets, sec)
|
||||
@ -106,9 +106,9 @@ func createStep(spec *engine.Spec, src *yaml.Container) *engine.Step {
|
||||
|
||||
// if the setting parameter is sources from the
|
||||
// secret we create a secret enviornment variable.
|
||||
if value.Secret.Name != "" {
|
||||
if value.Secret != "" {
|
||||
sec := &engine.SecretVar{
|
||||
Name: value.Secret.Name,
|
||||
Name: value.Secret,
|
||||
Env: key,
|
||||
}
|
||||
dst.Secrets = append(dst.Secrets, sec)
|
||||
|
@ -195,7 +195,7 @@ func toEnvironment(from *Container) map[string]*droneyaml.Variable {
|
||||
for _, val := range from.Secrets.Secrets {
|
||||
name := strings.ToUpper(val.Target)
|
||||
envs[name] = &droneyaml.Variable{
|
||||
Secret: droneyaml.FromSecret{Name: val.Source},
|
||||
Secret: val.Source,
|
||||
}
|
||||
}
|
||||
return envs
|
||||
|
17
yaml/env.go
17
yaml/env.go
@ -20,26 +20,25 @@ type (
|
||||
// to a secret.
|
||||
Variable struct {
|
||||
Value string `json:"value,omitempty"`
|
||||
Secret FromSecret `json:"from_secret,omitempty" yaml:"from_secret"`
|
||||
Secret string `json:"from_secret,omitempty" yaml:"from_secret"`
|
||||
}
|
||||
|
||||
// variable is a tempoary type used to unmarshal
|
||||
// variables with references to secrets.
|
||||
variable struct {
|
||||
FromSecret FromSecret `yaml:"from_secret"`
|
||||
Value string
|
||||
Secret string `yaml:"from_secret"`
|
||||
}
|
||||
)
|
||||
|
||||
// UnmarshalYAML implements yaml unmarshalling.
|
||||
func (v *Variable) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
d := new(variable)
|
||||
err := unmarshal(d)
|
||||
if err == nil && (d.FromSecret.Name != "" || d.FromSecret.Path != "") {
|
||||
v.Secret = d.FromSecret
|
||||
return nil
|
||||
err := unmarshal(&d.Value)
|
||||
if err != nil {
|
||||
err = unmarshal(d)
|
||||
}
|
||||
var s string
|
||||
err = unmarshal(&s)
|
||||
v.Value = s
|
||||
v.Value = d.Value
|
||||
v.Secret = d.Secret
|
||||
return err
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ func TestEnv(t *testing.T) {
|
||||
tests := []struct {
|
||||
yaml string
|
||||
value string
|
||||
name string
|
||||
path string
|
||||
from string
|
||||
}{
|
||||
{
|
||||
yaml: "bar",
|
||||
@ -23,12 +22,7 @@ func TestEnv(t *testing.T) {
|
||||
},
|
||||
{
|
||||
yaml: "from_secret: username",
|
||||
name: "username",
|
||||
},
|
||||
{
|
||||
yaml: "from_secret: { name: username, path: secret/data/docker }",
|
||||
name: "username",
|
||||
path: "secret/data/docker",
|
||||
from: "username",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
@ -42,11 +36,8 @@ func TestEnv(t *testing.T) {
|
||||
if got, want := out.Value, test.value; got != want {
|
||||
t.Errorf("Want variable value %q, got %q", want, got)
|
||||
}
|
||||
if got, want := out.Secret.Name, test.name; got != want {
|
||||
t.Errorf("Want variable from_secret.name %q, got %q", want, got)
|
||||
}
|
||||
if got, want := out.Secret.Path, test.path; got != want {
|
||||
t.Errorf("Want variable from_secret.path %q, got %q", want, got)
|
||||
if got, want := out.Secret, test.from; got != want {
|
||||
t.Errorf("Want variable from_secret %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ type (
|
||||
// to a secret.
|
||||
Parameter struct {
|
||||
Value interface{} `json:"value,omitempty"`
|
||||
Secret FromSecret `json:"from_secret,omitempty" yaml:"from_secret"`
|
||||
Secret string `json:"from_secret,omitempty" yaml:"from_secret"`
|
||||
}
|
||||
|
||||
// parameter is a tempoary type used to unmarshal
|
||||
// parameters with references to secrets.
|
||||
parameter struct {
|
||||
FromSecret FromSecret `yaml:"from_secret"`
|
||||
Secret string `yaml:"from_secret"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -34,8 +34,8 @@ type (
|
||||
func (p *Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
d := new(parameter)
|
||||
err := unmarshal(d)
|
||||
if err == nil && (d.FromSecret.Name != "" || d.FromSecret.Path != "") {
|
||||
p.Secret = d.FromSecret
|
||||
if err == nil && d.Secret != ""{
|
||||
p.Secret = d.Secret
|
||||
return nil
|
||||
}
|
||||
var i interface{}
|
||||
|
@ -5,7 +5,6 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
@ -15,32 +14,15 @@ func TestParam(t *testing.T) {
|
||||
tests := []struct {
|
||||
yaml string
|
||||
value interface{}
|
||||
name string
|
||||
path string
|
||||
from string
|
||||
}{
|
||||
{
|
||||
yaml: "bar",
|
||||
value: "bar",
|
||||
name: "",
|
||||
path: "",
|
||||
},
|
||||
{
|
||||
yaml: "[ bar ]",
|
||||
value: []interface{}{"bar"},
|
||||
name: "",
|
||||
path: "",
|
||||
},
|
||||
{
|
||||
yaml: "from_secret: username",
|
||||
value: nil,
|
||||
name: "username",
|
||||
path: "",
|
||||
},
|
||||
{
|
||||
yaml: "from_secret: { path: secret/data/docker, name: username }",
|
||||
value: nil,
|
||||
name: "username",
|
||||
path: "secret/data/docker",
|
||||
from: "username",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
@ -51,14 +33,11 @@ func TestParam(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if got, want := out.Value, test.value; !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Want value %q of type %T, got %q of type %T", want, want, got, got)
|
||||
if got, want := out.Value, test.value; got != want {
|
||||
t.Errorf("Want value %q, got %q", want, got)
|
||||
}
|
||||
if got, want := out.Secret.Name, test.name; got != want {
|
||||
t.Errorf("Want from_secret.name %q, got %q", want, got)
|
||||
}
|
||||
if got, want := out.Secret.Path, test.path; got != want {
|
||||
t.Errorf("Want from_secret.path %q, got %q", want, got)
|
||||
if got, want := out.Secret, test.from; got != want {
|
||||
t.Errorf("Want from_secret %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,12 +114,12 @@ func printEnviron(w writer, v map[string]*yaml.Variable) {
|
||||
w.IndentIncrease()
|
||||
for _, k := range keys {
|
||||
v := v[k]
|
||||
if v.Secret.Name == "" && v.Secret.Path == "" {
|
||||
if v.Secret == "" {
|
||||
w.WriteTagValue(k, v.Value)
|
||||
} else {
|
||||
w.WriteTag(k)
|
||||
w.IndentIncrease()
|
||||
printFromSecret(w, v.Secret)
|
||||
w.WriteTagValue("from_secret", v.Secret)
|
||||
w.IndentDecrease()
|
||||
}
|
||||
}
|
||||
@ -183,12 +183,12 @@ func printSettings(w writer, v map[string]*yaml.Parameter) {
|
||||
w.IndentIncrease()
|
||||
for _, k := range keys {
|
||||
v := v[k]
|
||||
if v.Secret.Name == "" && v.Secret.Path == "" {
|
||||
if v.Secret == "" {
|
||||
w.WriteTagValue(k, v.Value)
|
||||
} else {
|
||||
w.WriteTag(k)
|
||||
w.IndentIncrease()
|
||||
printFromSecret(w, v.Secret)
|
||||
w.WriteTagValue("from_secret", v.Secret)
|
||||
w.IndentDecrease()
|
||||
}
|
||||
}
|
||||
@ -208,19 +208,6 @@ func printVolumeMounts(w writer, v []*yaml.VolumeMount) {
|
||||
}
|
||||
}
|
||||
|
||||
// helper function pretty prints the from_secret sequence.
|
||||
func printFromSecret(w writer, v yaml.FromSecret) {
|
||||
if v.Path == "" {
|
||||
w.WriteTagValue("from_secret", v.Name)
|
||||
} else {
|
||||
w.WriteTag("from_secret")
|
||||
w.IndentIncrease()
|
||||
w.WriteTagValue("path", v.Path)
|
||||
w.WriteTagValue("name", v.Name)
|
||||
w.IndentDecrease()
|
||||
}
|
||||
}
|
||||
|
||||
// helper function returns true if the Build block should
|
||||
// be printed in short form.
|
||||
func shortBuild(b *yaml.Build) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user