github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/addons_artifacts.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 Artifacts struct { 20 Enabled bool `yaml:"enabled,omitempty"` 21 Bucket string `yaml:"bucket,omitempty"` 22 Key *Secure `yaml:"key,omitempty"` 23 Secret *Secure `yaml:"secret,omitempty"` 24 Region string `yaml:"region,omitempty"` 25 Paths []string `yaml:"paths,omitempty"` 26 Branch string `yaml:"branch,omitempty"` 27 LogFormat string `yaml:"log_format,omitempty"` 28 TargetPaths []string `yaml:"target_paths,omitempty"` 29 Debug bool `yaml:"debug,omitempty"` 30 Concurrency int `yaml:"concurrency,omitempty"` 31 MaxSize int64 `yaml:"max_size,omitempty"` 32 Permissions string `yaml:"permissions,omitempty"` 33 WorkingDir string `yaml:"working_dir,omitempty"` 34 CacheControl string `yaml:"cache_control,omitempty"` 35 } 36 37 // UnmarshalYAML implements the unmarshal interface. 38 func (v *Artifacts) UnmarshalYAML(unmarshal func(interface{}) error) error { 39 var out1 bool 40 var out2 = struct { 41 Enabled *bool `yaml:"enabled"` 42 Bucket string `yaml:"bucket,omitempty"` 43 Key *Secure `yaml:"key,omitempty"` 44 Secret *Secure `yaml:"secret,omitempty"` 45 Region string `yaml:"region,omitempty"` 46 Paths Stringorslice `yaml:"paths,omitempty"` 47 Branch string `yaml:"branch,omitempty"` 48 LogFormat string `yaml:"log_format,omitempty"` 49 TargetPaths Stringorslice `yaml:"target_paths,omitempty"` 50 Debug bool `yaml:"debug,omitempty"` 51 Concurrency int `yaml:"concurrency,omitempty"` 52 MaxSize int64 `yaml:"max_size,omitempty"` 53 Permissions string `yaml:"permissions,omitempty"` 54 WorkingDir string `yaml:"working_dir,omitempty"` 55 CacheControl string `yaml:"cache_control,omitempty"` 56 // key aliases 57 AWSAccessKeyID *Secure `yaml:"aws_access_key_id,omitempty"` 58 AWSAccessKey *Secure `yaml:"aws_access_key,omitempty"` 59 AccessKeyID *Secure `yaml:"access_key_id,omitempty"` 60 AccessKey *Secure `yaml:"access_key,omitempty"` 61 // secret aliases 62 AWSSecretAccessKey *Secure `yaml:"aws_secret_access_key,omitempty"` 63 AWSSecretKey *Secure `yaml:"aws_secret_key,omitempty"` 64 SecretAccessKey *Secure `yaml:"secret_access_key,omitempty"` 65 SecretKey *Secure `yaml:"secret_key,omitempty"` 66 }{} 67 if err := unmarshal(&out1); err == nil { 68 v.Enabled = out1 69 return nil 70 } 71 if err := unmarshal(&out2); err == nil { 72 v.Enabled = true 73 if out2.Enabled != nil { 74 v.Enabled = *out2.Enabled 75 } 76 v.Bucket = out2.Bucket 77 v.Key = out2.Key 78 v.Secret = out2.Secret 79 v.Region = out2.Region 80 v.Paths = out2.Paths 81 v.Branch = out2.Branch 82 v.LogFormat = out2.LogFormat 83 v.TargetPaths = out2.TargetPaths 84 v.Debug = out2.Debug 85 v.Concurrency = out2.Concurrency 86 v.MaxSize = out2.MaxSize 87 v.Permissions = out2.Permissions 88 v.WorkingDir = out2.WorkingDir 89 v.CacheControl = out2.CacheControl 90 switch { 91 case out2.AWSAccessKeyID != nil: 92 v.Key = out2.AWSAccessKeyID 93 case out2.AWSAccessKey != nil: 94 v.Key = out2.AWSAccessKey 95 case out2.AccessKeyID != nil: 96 v.Key = out2.AccessKeyID 97 case out2.AccessKey != nil: 98 v.Key = out2.AccessKey 99 } 100 switch { 101 case out2.AWSSecretAccessKey != nil: 102 v.Secret = out2.AWSSecretAccessKey 103 case out2.AWSSecretKey != nil: 104 v.Secret = out2.AWSSecretKey 105 case out2.SecretAccessKey != nil: 106 v.Secret = out2.SecretAccessKey 107 case out2.SecretKey != nil: 108 v.Secret = out2.SecretKey 109 } 110 return nil 111 } 112 return errors.New("failed to unmarshal artifacts") 113 }