2019-02-10 19:00:16 +00:00
|
|
|
// Copyright 2019 Drone IO, Inc.
|
2019-02-22 00:59:17 +00:00
|
|
|
//
|
2019-02-10 19:00:16 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2019-02-22 00:59:17 +00:00
|
|
|
//
|
2019-02-10 19:00:16 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2019-02-22 00:59:17 +00:00
|
|
|
//
|
2019-02-10 19:00:16 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Parameter represents an configuration parameter that
|
|
|
|
// can be defined as a literal or as a reference
|
|
|
|
// to a secret.
|
|
|
|
Parameter struct {
|
|
|
|
Value interface{} `json:"value,omitempty"`
|
2019-02-22 00:59:17 +00:00
|
|
|
Secret string `json:"from_secret,omitempty" yaml:"from_secret"`
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parameter is a tempoary type used to unmarshal
|
|
|
|
// parameters with references to secrets.
|
|
|
|
parameter struct {
|
2019-02-22 00:59:17 +00:00
|
|
|
Secret string `yaml:"from_secret"`
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// UnmarshalYAML implements yaml unmarshalling.
|
|
|
|
func (p *Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
d := new(parameter)
|
|
|
|
err := unmarshal(d)
|
2019-02-22 00:59:17 +00:00
|
|
|
if err == nil && d.Secret != ""{
|
|
|
|
p.Secret = d.Secret
|
2019-01-22 23:44:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var i interface{}
|
|
|
|
err = unmarshal(&i)
|
|
|
|
p.Value = i
|
|
|
|
return err
|
|
|
|
}
|