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