7
7
"context"
8
8
"fmt"
9
9
"net/url"
10
+ "reflect"
10
11
"time"
11
12
)
12
13
@@ -42,17 +43,18 @@ type adminSentinelVersions struct {
42
43
43
44
// AdminSentinelVersion represents a Sentinel Version
44
45
type AdminSentinelVersion struct {
45
- ID string `jsonapi:"primary,sentinel-versions"`
46
- Version string `jsonapi:"attr,version"`
47
- URL string `jsonapi:"attr,url"`
48
- SHA string `jsonapi:"attr,sha"`
49
- Deprecated bool `jsonapi:"attr,deprecated"`
50
- DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
51
- Official bool `jsonapi:"attr,official"`
52
- Enabled bool `jsonapi:"attr,enabled"`
53
- Beta bool `jsonapi:"attr,beta"`
54
- Usage int `jsonapi:"attr,usage"`
55
- CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
46
+ ID string `jsonapi:"primary,sentinel-versions"`
47
+ Version string `jsonapi:"attr,version"`
48
+ URL string `jsonapi:"attr,url,omitempty"`
49
+ SHA string `jsonapi:"attr,sha,omitempty"`
50
+ Deprecated bool `jsonapi:"attr,deprecated"`
51
+ DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
52
+ Official bool `jsonapi:"attr,official"`
53
+ Enabled bool `jsonapi:"attr,enabled"`
54
+ Beta bool `jsonapi:"attr,beta"`
55
+ Usage int `jsonapi:"attr,usage"`
56
+ CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
57
+ Archs []* ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
56
58
}
57
59
58
60
// AdminSentinelVersionsListOptions represents the options for listing
@@ -69,28 +71,30 @@ type AdminSentinelVersionsListOptions struct {
69
71
70
72
// AdminSentinelVersionCreateOptions for creating an Sentinel version.
71
73
type AdminSentinelVersionCreateOptions struct {
72
- Type string `jsonapi:"primary,sentinel-versions"`
73
- Version string `jsonapi:"attr,version"` // Required
74
- URL string `jsonapi:"attr,url"` // Required
75
- SHA string `jsonapi:"attr,sha"` // Required
76
- Official * bool `jsonapi:"attr,official,omitempty"`
77
- Deprecated * bool `jsonapi:"attr,deprecated,omitempty"`
78
- DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
79
- Enabled * bool `jsonapi:"attr,enabled,omitempty"`
80
- Beta * bool `jsonapi:"attr,beta,omitempty"`
74
+ Type string `jsonapi:"primary,sentinel-versions"`
75
+ Version string `jsonapi:"attr,version"` // Required
76
+ URL string `jsonapi:"attr,url,omitempty"` // Required w/ SHA unless Archs are provided
77
+ SHA string `jsonapi:"attr,sha,omitempty"` // Required w/ URL unless Archs are provided
78
+ Official * bool `jsonapi:"attr,official,omitempty"`
79
+ Deprecated * bool `jsonapi:"attr,deprecated,omitempty"`
80
+ DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
81
+ Enabled * bool `jsonapi:"attr,enabled,omitempty"`
82
+ Beta * bool `jsonapi:"attr,beta,omitempty"`
83
+ Archs []* ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"` // Required unless URL and SHA are provided
81
84
}
82
85
83
86
// AdminSentinelVersionUpdateOptions for updating Sentinel version.
84
87
type AdminSentinelVersionUpdateOptions struct {
85
- Type string `jsonapi:"primary,sentinel-versions"`
86
- Version * string `jsonapi:"attr,version,omitempty"`
87
- URL * string `jsonapi:"attr,url,omitempty"`
88
- SHA * string `jsonapi:"attr,sha,omitempty"`
89
- Official * bool `jsonapi:"attr,official,omitempty"`
90
- Deprecated * bool `jsonapi:"attr,deprecated,omitempty"`
91
- DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
92
- Enabled * bool `jsonapi:"attr,enabled,omitempty"`
93
- Beta * bool `jsonapi:"attr,beta,omitempty"`
88
+ Type string `jsonapi:"primary,sentinel-versions"`
89
+ Version * string `jsonapi:"attr,version,omitempty"`
90
+ URL * string `jsonapi:"attr,url,omitempty"`
91
+ SHA * string `jsonapi:"attr,sha,omitempty"`
92
+ Official * bool `jsonapi:"attr,official,omitempty"`
93
+ Deprecated * bool `jsonapi:"attr,deprecated,omitempty"`
94
+ DeprecatedReason * string `jsonapi:"attr,deprecated-reason,omitempty"`
95
+ Enabled * bool `jsonapi:"attr,enabled,omitempty"`
96
+ Beta * bool `jsonapi:"attr,beta,omitempty"`
97
+ Archs []* ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
94
98
}
95
99
96
100
// AdminSentinelVersionsList represents a list of Sentinel versions.
@@ -192,18 +196,29 @@ func (a *adminSentinelVersions) Delete(ctx context.Context, id string) error {
192
196
}
193
197
194
198
func (o AdminSentinelVersionCreateOptions ) valid () error {
195
- if (o == AdminSentinelVersionCreateOptions {}) {
199
+ if (reflect . DeepEqual ( o , AdminSentinelVersionCreateOptions {}) ) {
196
200
return ErrRequiredSentinelVerCreateOps
197
201
}
198
202
if o .Version == "" {
199
203
return ErrRequiredVersion
200
204
}
201
- if o . URL == "" {
202
- return ErrRequiredURL
205
+ if ! o . validArch () {
206
+ return ErrRequiredArchsOrURLAndSha
203
207
}
204
- if o .SHA == "" {
205
- return ErrRequiredSha
208
+ return nil
209
+ }
210
+
211
+ func (o AdminSentinelVersionCreateOptions ) validArch () bool {
212
+ if o .Archs == nil && o .URL != "" && o .SHA != "" {
213
+ return true
206
214
}
207
215
208
- return nil
216
+ emptyToolVersionFields := o .URL == "" && o .SHA == ""
217
+
218
+ for _ , a := range o .Archs {
219
+ if ! validArch (a ) || ! emptyToolVersionFields && (o .URL != a .URL || o .SHA != a .Sha ) {
220
+ return false
221
+ }
222
+ }
223
+ return true
209
224
}
0 commit comments