19
19
package agent
20
20
21
21
import (
22
- "encoding/json"
23
22
"errors"
24
23
"fmt"
25
24
"io/fs"
@@ -30,6 +29,8 @@ import (
30
29
"github.com/google/renameio/v2"
31
30
"github.com/gravitational/trace"
32
31
"gopkg.in/yaml.v3"
32
+
33
+ "github.com/gravitational/teleport/lib/autoupdate"
33
34
)
34
35
35
36
const (
@@ -59,8 +60,8 @@ type UpdateSpec struct {
59
60
Proxy string `yaml:"proxy"`
60
61
// Group specifies the update group identifier for the agent.
61
62
Group string `yaml:"group,omitempty"`
62
- // URLTemplate for the Teleport tgz download URL.
63
- URLTemplate string `yaml:"url_template ,omitempty"`
63
+ // BaseURL is CDN base URL used for the Teleport tgz download URL.
64
+ BaseURL string `yaml:"base_url ,omitempty"`
64
65
// Enabled controls whether auto-updates are enabled.
65
66
Enabled bool `yaml:"enabled"`
66
67
// Pinned controls whether the active_version is pinned.
@@ -84,13 +85,13 @@ type Revision struct {
84
85
// Version is the version of Teleport.
85
86
Version string `yaml:"version" json:"version"`
86
87
// Flags describe the edition of Teleport.
87
- Flags InstallFlags `yaml:"flags,flow,omitempty" json:"flags,omitempty"`
88
+ Flags autoupdate. InstallFlags `yaml:"flags,flow,omitempty" json:"flags,omitempty"`
88
89
}
89
90
90
91
// NewRevision create a Revision.
91
92
// If version is not set, no flags are returned.
92
93
// This ensures that all Revisions without versions are zero-valued.
93
- func NewRevision (version string , flags InstallFlags ) Revision {
94
+ func NewRevision (version string , flags autoupdate. InstallFlags ) Revision {
94
95
if version != "" {
95
96
return Revision {
96
97
Version : version ,
@@ -113,16 +114,16 @@ func NewRevisionFromDir(dir string) (Revision, error) {
113
114
}
114
115
switch flags := parts [1 :]; len (flags ) {
115
116
case 2 :
116
- if flags [1 ] != FlagFIPS .DirFlag () {
117
+ if flags [1 ] != autoupdate . FlagFIPS .DirFlag () {
117
118
break
118
119
}
119
- out .Flags |= FlagFIPS
120
+ out .Flags |= autoupdate . FlagFIPS
120
121
fallthrough
121
122
case 1 :
122
- if flags [0 ] != FlagEnterprise .DirFlag () {
123
+ if flags [0 ] != autoupdate . FlagEnterprise .DirFlag () {
123
124
break
124
125
}
125
- out .Flags |= FlagEnterprise
126
+ out .Flags |= autoupdate . FlagEnterprise
126
127
fallthrough
127
128
case 0 :
128
129
return out , nil
@@ -135,11 +136,11 @@ func (r Revision) Dir() string {
135
136
// Do not change the order of these statements.
136
137
// Otherwise, installed versions will no longer match update.yaml.
137
138
var suffix string
138
- if r .Flags & (FlagEnterprise | FlagFIPS ) != 0 {
139
- suffix += "_" + FlagEnterprise .DirFlag ()
139
+ if r .Flags & (autoupdate . FlagEnterprise | autoupdate . FlagFIPS ) != 0 {
140
+ suffix += "_" + autoupdate . FlagEnterprise .DirFlag ()
140
141
}
141
- if r .Flags & FlagFIPS != 0 {
142
- suffix += "_" + FlagFIPS .DirFlag ()
142
+ if r .Flags & autoupdate . FlagFIPS != 0 {
143
+ suffix += "_" + autoupdate . FlagFIPS .DirFlag ()
143
144
}
144
145
return r .Version + suffix
145
146
}
@@ -203,16 +204,16 @@ func validateConfigSpec(spec *UpdateSpec, override OverrideConfig) error {
203
204
if override .Group != "" {
204
205
spec .Group = override .Group
205
206
}
206
- switch override .URLTemplate {
207
+ switch override .BaseURL {
207
208
case "" :
208
209
case "default" :
209
- spec .URLTemplate = ""
210
+ spec .BaseURL = ""
210
211
default :
211
- spec .URLTemplate = override .URLTemplate
212
+ spec .BaseURL = override .BaseURL
212
213
}
213
- if spec .URLTemplate != "" &&
214
- ! strings .HasPrefix (strings .ToLower (spec .URLTemplate ), "https://" ) {
215
- return trace .Errorf ("Teleport download URL must use TLS (https://)" )
214
+ if spec .BaseURL != "" &&
215
+ ! strings .HasPrefix (strings .ToLower (spec .BaseURL ), "https://" ) {
216
+ return trace .Errorf ("Teleport download base URL %s must use TLS (https://)" , spec . BaseURL )
216
217
}
217
218
if override .Enabled {
218
219
spec .Enabled = true
@@ -239,89 +240,3 @@ type FindResp struct {
239
240
// Jitter duration before an automated install
240
241
Jitter time.Duration `yaml:"jitter"`
241
242
}
242
-
243
- // InstallFlags sets flags for the Teleport installation
244
- type InstallFlags int
245
-
246
- const (
247
- // FlagEnterprise installs enterprise Teleport
248
- FlagEnterprise InstallFlags = 1 << iota
249
- // FlagFIPS installs FIPS Teleport
250
- FlagFIPS
251
- )
252
-
253
- // NewInstallFlagsFromStrings returns InstallFlags given a slice of human-readable strings.
254
- func NewInstallFlagsFromStrings (s []string ) InstallFlags {
255
- var out InstallFlags
256
- for _ , f := range s {
257
- for _ , flag := range []InstallFlags {
258
- FlagEnterprise ,
259
- FlagFIPS ,
260
- } {
261
- if f == flag .String () {
262
- out |= flag
263
- }
264
- }
265
- }
266
- return out
267
- }
268
-
269
- // Strings converts InstallFlags to a slice of human-readable strings.
270
- func (i InstallFlags ) Strings () []string {
271
- var out []string
272
- for _ , flag := range []InstallFlags {
273
- FlagEnterprise ,
274
- FlagFIPS ,
275
- } {
276
- if i & flag != 0 {
277
- out = append (out , flag .String ())
278
- }
279
- }
280
- return out
281
- }
282
-
283
- // String returns the string representation of a single InstallFlag flag, or "Unknown".
284
- func (i InstallFlags ) String () string {
285
- switch i {
286
- case 0 :
287
- return ""
288
- case FlagEnterprise :
289
- return "Enterprise"
290
- case FlagFIPS :
291
- return "FIPS"
292
- }
293
- return "Unknown"
294
- }
295
-
296
- // DirFlag returns the directory path representation of a single InstallFlag flag, or "unknown".
297
- func (i InstallFlags ) DirFlag () string {
298
- switch i {
299
- case 0 :
300
- return ""
301
- case FlagEnterprise :
302
- return "ent"
303
- case FlagFIPS :
304
- return "fips"
305
- }
306
- return "unknown"
307
- }
308
-
309
- func (i InstallFlags ) MarshalYAML () (any , error ) {
310
- return i .Strings (), nil
311
- }
312
-
313
- func (i InstallFlags ) MarshalJSON () ([]byte , error ) {
314
- return json .Marshal (i .Strings ())
315
- }
316
-
317
- func (i * InstallFlags ) UnmarshalYAML (n * yaml.Node ) error {
318
- var s []string
319
- if err := n .Decode (& s ); err != nil {
320
- return trace .Wrap (err )
321
- }
322
- if i == nil {
323
- return trace .BadParameter ("nil install flags while parsing YAML" )
324
- }
325
- * i = NewInstallFlagsFromStrings (s )
326
- return nil
327
- }
0 commit comments