github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/addons_sauce.go (about)

     1  // Copyright 2022 Harness, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package yaml
    16  
    17  import "errors"
    18  
    19  type Sauce struct {
    20  	Enabled          bool    `yaml:"enabled,omitempty"`
    21  	Username         *Secure `yaml:"username,omitempty"`
    22  	AccessKey        *Secure `yaml:"access_key,omitempty"`
    23  	DirectDomains    string  `yaml:"direct_domains,omitempty"`
    24  	TunnelDomains    string  `yaml:"tunnel_domains,omitempty"`
    25  	NoSSLBumpDomains string  `yaml:"no_ssl_bump_domains,omitempty"`
    26  }
    27  
    28  // UnmarshalYAML implements the unmarshal interface.
    29  func (v *Sauce) UnmarshalYAML(unmarshal func(interface{}) error) error {
    30  	var out1 bool
    31  	var out2 = struct {
    32  		Enabled          *bool   `yaml:"enabled"`
    33  		Username         *Secure `yaml:"username"`
    34  		AccessKey        *Secure `yaml:"access_key"`
    35  		DirectDomains    string  `yaml:"direct_domains"`
    36  		TunnelDomains    string  `yaml:"tunnel_domains"`
    37  		NoSSLBumpDomains string  `yaml:"no_ssl_bump_domains"`
    38  	}{}
    39  	if err := unmarshal(&out1); err == nil {
    40  		v.Enabled = out1
    41  		return nil
    42  	}
    43  	if err := unmarshal(&out2); err == nil {
    44  		v.Enabled = true
    45  		if out2.Enabled != nil {
    46  			v.Enabled = *out2.Enabled
    47  		}
    48  		v.Username = out2.Username
    49  		v.AccessKey = out2.AccessKey
    50  		v.DirectDomains = out2.DirectDomains
    51  		v.TunnelDomains = out2.TunnelDomains
    52  		v.NoSSLBumpDomains = out2.NoSSLBumpDomains
    53  		return nil
    54  	}
    55  	return errors.New("failed to unmarshal sauce_connect")
    56  }