github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/addons_browserstack.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 Browserstack struct { 20 Enabled bool `yaml:"enabled,omitempty"` 21 Username *Secure `yaml:"username,omitempty"` 22 AccessKey *Secure `yaml:"access_key,omitempty"` 23 ForceLocal bool `yaml:"forcelocal,omitempty"` 24 Only string `yaml:"only,omitempty"` 25 AppPath string `yaml:"app_path,omitempty"` 26 ProxyHost string `yaml:"proxyHost,omitempty"` 27 ProxyPort string `yaml:"proxyPort,omitempty"` 28 ProxyUser string `yaml:"proxyUser,omitempty"` 29 ProxyPass *Secure `yaml:"proxyPass,omitempty"` 30 } 31 32 // UnmarshalYAML implements the unmarshal interface. 33 func (v *Browserstack) UnmarshalYAML(unmarshal func(interface{}) error) error { 34 var out1 bool 35 var out2 = struct { 36 Enabled *bool `yaml:"enabled"` 37 Username *Secure `yaml:"username,omitempty"` 38 AccessKey *Secure `yaml:"access_key,omitempty"` 39 ForceLocal bool `yaml:"forcelocal,omitempty"` 40 Only string `yaml:"only,omitempty"` 41 AppPath string `yaml:"app_path,omitempty"` 42 ProxyHost string `yaml:"proxyHost,omitempty"` 43 ProxyPort string `yaml:"proxyPort,omitempty"` 44 ProxyUser string `yaml:"proxyUser,omitempty"` 45 ProxyPass *Secure `yaml:"proxyPass,omitempty"` 46 }{} 47 if err := unmarshal(&out1); err == nil { 48 v.Enabled = out1 49 return nil 50 } 51 if err := unmarshal(&out2); err == nil { 52 v.Enabled = true 53 if out2.Enabled != nil { 54 v.Enabled = *out2.Enabled 55 } 56 v.Username = out2.Username 57 v.AccessKey = out2.AccessKey 58 v.ForceLocal = out2.ForceLocal 59 v.Only = out2.Only 60 v.AppPath = out2.AppPath 61 v.ProxyHost = out2.ProxyHost 62 v.ProxyPort = out2.ProxyPort 63 v.ProxyUser = out2.ProxyUser 64 v.ProxyPass = out2.ProxyPass 65 return nil 66 } 67 return errors.New("failed to unmarshal browserstack") 68 }