-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathmodels.go
More file actions
104 lines (88 loc) · 3.44 KB
/
models.go
File metadata and controls
104 lines (88 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package s3resource
import (
"sort"
"strings"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
)
type Source struct {
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
SessionToken string `json:"session_token"`
AwsRoleARN string `json:"aws_role_arn"`
Bucket string `json:"bucket"`
Regexp string `json:"regexp"`
VersionedFile string `json:"versioned_file"`
Private bool `json:"private"`
RegionName string `json:"region_name"`
UseAwsCredsProvider bool `json:"enable_aws_creds_provider"`
//Deprecated: Not needed since upgrading to the v2 AWS Go SDK
CloudfrontURL string `json:"cloudfront_url"`
Endpoint string `json:"endpoint"`
DisableSSL bool `json:"disable_ssl"`
ServerSideEncryption string `json:"server_side_encryption"`
SSEKMSKeyId string `json:"sse_kms_key_id"`
UseV2Signing bool `json:"use_v2_signing"`
SkipSSLVerification bool `json:"skip_ssl_verification"`
CABundle string `json:"ca_bundle"`
SkipDownload bool `json:"skip_download"`
InitialVersion string `json:"initial_version"`
InitialPath string `json:"initial_path"`
InitialContentText string `json:"initial_content_text"`
InitialContentBinary string `json:"initial_content_binary"`
DisableMultipart bool `json:"disable_multipart"`
UsePathStyle bool `json:"use_path_style"`
SkipS3Checksums bool `json:"skip_s3_checksums"`
ChecksumAlgorithm string `json:"checksum_algorithm"`
}
func (source Source) IsValid() (bool, string) {
if source.Regexp != "" && source.VersionedFile != "" {
return false, "please specify either regexp or versioned_file"
}
if source.Regexp != "" && source.InitialVersion != "" {
return false, "please use initial_path when regexp is set"
}
if source.VersionedFile != "" && source.InitialPath != "" {
return false, "please use initial_version when versioned_file is set"
}
if source.SkipSSLVerification && source.CABundle != "" {
return false, "please do not use ca_bundle when skip_ssl_verification is set"
}
if source.InitialContentText != "" && source.InitialContentBinary != "" {
return false, "please use intial_content_text or initial_content_binary but not both"
}
hasInitialContent := source.InitialContentText != "" || source.InitialContentBinary != ""
if hasInitialContent && source.InitialVersion == "" && source.InitialPath == "" {
return false, "please specify initial_version or initial_path if initial content is set"
}
// Validate checksum algorithm if specified
if source.ChecksumAlgorithm != "" {
validAlgorithms := types.ChecksumAlgorithm("").Values()
valid := false
for _, alg := range validAlgorithms {
if string(alg) == source.ChecksumAlgorithm {
valid = true
break
}
}
if !valid {
validValues := make([]string, len(validAlgorithms))
for i, alg := range validAlgorithms {
validValues[i] = string(alg)
}
sort.Strings(validValues)
return false, "checksum_algorithm must be one of: " + strings.Join(validValues, ", ")
}
if source.SkipS3Checksums {
return false, "checksum_algorithm cannot be used when skip_s3_checksums is true"
}
}
return true, ""
}
type Version struct {
Path string `json:"path,omitempty"`
VersionID string `json:"version_id,omitempty"`
}
type MetadataPair struct {
Name string `json:"name"`
Value string `json:"value"`
}