@@ -49,21 +49,22 @@ type WorkflowInclude struct {
49
49
ValidationState string
50
50
Contents string
51
51
Hash string
52
- Workflow * StackupWorkflow
52
+ // Workflow *StackupWorkflow
53
53
}
54
54
55
55
type WorkflowSettings struct {
56
56
Defaults * WorkflowSettingsDefaults `yaml:"defaults"`
57
57
ExitOnChecksumMismatch bool `yaml:"exit-on-checksum-mismatch"`
58
58
DotEnvFiles []string `yaml:"dotenv"`
59
- Cache struct {
60
- TtlMinutes int `yaml:"ttl-minutes"`
61
- } `yaml:"cache"`
62
- Domains struct {
59
+ Cache * WorkflowSettingsCache `yaml:"cache"`
60
+ Domains struct {
63
61
Allowed []string `yaml:"allowed"`
64
62
} `yaml:"domains"`
65
63
}
66
64
65
+ type WorkflowSettingsCache struct {
66
+ TtlMinutes int `yaml:"ttl-minutes"`
67
+ }
67
68
type WorkflowSettingsDefaults struct {
68
69
Tasks * WorkflowSettingsDefaultsTasks `yaml:"tasks"`
69
70
}
@@ -151,13 +152,13 @@ func (wi *WorkflowInclude) ValidateChecksum(contents string) (bool, error) {
151
152
algorithm := ""
152
153
storedChecksum := ""
153
154
checksumContents := ""
154
- hashUrl := ""
155
155
156
156
for _ , url := range checksumUrls {
157
- if wi .Workflow .Cache .Has (url ) && ! wi .Workflow .Cache .IsExpired (url ) {
158
- hashUrl = url
159
- checksumContents = wi .Workflow .Cache .Get (url )
160
- fmt .Printf ("using cached checksum file %s\n " , url )
157
+
158
+ if ! App .Workflow .Cache .IsExpired (url ) {
159
+ wi .ChecksumUrl = url
160
+ checksumContents = App .Workflow .Cache .Get (url )
161
+ // fmt.Printf("using cached checksum file %s\n", url)
161
162
break
162
163
}
163
164
@@ -166,22 +167,27 @@ func (wi *WorkflowInclude) ValidateChecksum(contents string) (bool, error) {
166
167
continue
167
168
}
168
169
170
+ wi .ChecksumUrl = url
171
+
169
172
if checksumContents != "" {
170
- hashUrl = url
171
- wi .Workflow .Cache .Set (url , checksumContents , wi . Workflow . Settings . Cache . TtlMinutes )
172
- fmt .Printf ("using non-cached checksum file %s\n " , url )
173
+ // fmt.Printf("using checksum file %s\n", wi.ChecksumUrl)
174
+ App .Workflow .Cache .Set (url , checksumContents , 3 )
175
+ // fmt.Printf("using non-cached checksum file %s\n", url)
173
176
break
174
177
}
175
178
}
176
179
177
180
if checksumContents != "" {
178
181
storedChecksum = wi .getChecksumFromContents (checksumContents )
179
182
180
- wi .ChecksumUrl = hashUrl
183
+ // wi.ChecksumUrl = hashUrl
184
+ // fmt.Println("checksum url: " + wi.ChecksumUrl)
181
185
algorithm = wi .GetChecksumAlgorithm ()
182
186
}
183
187
184
- if algorithm == "unknown" {
188
+ // algorithm = "sha256"
189
+
190
+ if algorithm == "unknown" || algorithm == "" {
185
191
return false , fmt .Errorf ("unable to find valid checksum file for %s" , wi .DisplayUrl ())
186
192
}
187
193
@@ -318,7 +324,7 @@ func (workflow *StackupWorkflow) reversePreconditions(items []*Precondition) []*
318
324
}
319
325
320
326
func (workflow * StackupWorkflow ) Initialize () {
321
- workflow .Cache = cache .CreateCache (utils . GetProjectName () )
327
+ workflow .Cache = cache .CreateCache ("" )
322
328
323
329
// generate uuids for each task as the initial step, as other code below relies on a uuid existing
324
330
for _ , task := range workflow .Tasks {
@@ -336,6 +342,7 @@ func (workflow *StackupWorkflow) Initialize() {
336
342
if workflow .Settings == nil {
337
343
workflow .Settings = & WorkflowSettings {
338
344
DotEnvFiles : []string {".env" },
345
+ Cache : & WorkflowSettingsCache {TtlMinutes : 5 },
339
346
Defaults : & WorkflowSettingsDefaults {
340
347
Tasks : & WorkflowSettingsDefaultsTasks {
341
348
Silent : false ,
@@ -371,7 +378,7 @@ func (workflow *StackupWorkflow) Initialize() {
371
378
372
379
// initialize the includes
373
380
for _ , inc := range workflow .Includes {
374
- inc .Initialize (workflow )
381
+ inc .Initialize ()
375
382
}
376
383
377
384
workflow .ProcessIncludes ()
@@ -416,9 +423,9 @@ func (workflow *StackupWorkflow) ProcessIncludes() {
416
423
var wg sync.WaitGroup
417
424
for _ , include := range workflow .Includes {
418
425
wg .Add (1 )
419
- go func (include * WorkflowInclude ) {
426
+ go func (inc * WorkflowInclude ) {
420
427
defer wg .Done ()
421
- workflow .ProcessInclude (include )
428
+ workflow .ProcessInclude (inc )
422
429
}(include )
423
430
}
424
431
wg .Wait ()
@@ -429,17 +436,16 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
429
436
return false
430
437
}
431
438
432
- var contents string
433
439
var err error
434
440
435
441
if workflow .Cache .Has (include .DisplayName ()) && ! workflow .Cache .IsExpired (include .DisplayName ()) {
436
442
include .Contents = workflow .Cache .Get (include .DisplayName ())
437
443
include .Hash = workflow .Cache .GetHash (include .DisplayName ())
438
- fmt .Println ("loaded from cache" )
444
+ // fmt.Println("loaded from cache")
439
445
}
440
446
441
447
if ! workflow .Cache .Has (include .DisplayName ()) || workflow .Cache .IsExpired (include .DisplayName ()) {
442
- fmt .Println ("not loaded from cache" )
448
+ // fmt.Println("not loaded from cache")
443
449
if include .IsLocalFile () {
444
450
include .Contents , err = utils .GetFileContents (include .Filename ())
445
451
} else if include .IsRemoteUrl () {
@@ -453,7 +459,7 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
453
459
}
454
460
455
461
include .Hash = checksums .CalculateSha256Hash (include .Contents )
456
- workflow .Cache .Set (include .DisplayName (), include .Contents , workflow . Settings . Cache . TtlMinutes )
462
+ workflow .Cache .Set (include .DisplayName (), include .Contents , 3 )
457
463
}
458
464
459
465
// fmt.Printf("value: %v\n", workflow.Cache.Get(include.DisplayName()))
@@ -473,8 +479,8 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
473
479
474
480
if include .IsRemoteUrl () {
475
481
if * include .VerifyChecksum == true || include .VerifyChecksum == nil {
476
- //support.StatusMessage("Validating checksum for remote include: "+include.DisplayUrl(), false)
477
- validated , err := include .ValidateChecksum (include .Contents )
482
+ // support.StatusMessage("Validating checksum for remote include: "+include.DisplayUrl(), false)
483
+ validated , _ := include .ValidateChecksum (include .Contents )
478
484
479
485
if include .ChecksumIsValid != nil && * include .ChecksumIsValid == true {
480
486
include .ValidationState = "checksum validated"
@@ -484,10 +490,10 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
484
490
include .ValidationState = "checksum mismatch"
485
491
}
486
492
487
- if err != nil {
488
- fmt .Println (err )
489
- return false
490
- }
493
+ // if err != nil {
494
+ // fmt.Println(err)
495
+ // return false
496
+ // }
491
497
492
498
if ! validated {
493
499
if App .Workflow .Settings .ExitOnChecksumMismatch {
@@ -500,29 +506,29 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
500
506
}
501
507
502
508
template := & IncludedTemplate {}
503
- err = yaml .Unmarshal ([]byte (contents ), template )
509
+ err = yaml .Unmarshal ([]byte (include . Contents ), template )
504
510
505
511
if err != nil {
506
512
fmt .Println (err )
507
513
return false
508
514
}
509
515
510
516
if len (template .Init ) > 0 {
511
- workflow .Init += "\n " + template .Init
517
+ App . Workflow .Init += "\n " + template .Init
512
518
}
513
519
514
520
// prepend the included preconditions; we reverse the order of the preconditions in the included file,
515
521
// then reverse the existing preconditions, append them, then reverse the workflow preconditions again
516
522
// to achieve the correct order.
517
- App .Workflow .Preconditions = workflow .reversePreconditions (App .Workflow .Preconditions )
518
- template .Preconditions = workflow .reversePreconditions (template .Preconditions )
523
+ App .Workflow .Preconditions = App . Workflow .reversePreconditions (App .Workflow .Preconditions )
524
+ template .Preconditions = App . Workflow .reversePreconditions (template .Preconditions )
519
525
520
526
for _ , p := range template .Preconditions {
521
527
p .FromRemote = true
522
528
App .Workflow .Preconditions = append (App .Workflow .Preconditions , p )
523
529
}
524
530
525
- App .Workflow .Preconditions = workflow .reversePreconditions (App .Workflow .Preconditions )
531
+ App .Workflow .Preconditions = App . Workflow .reversePreconditions (App .Workflow .Preconditions )
526
532
527
533
for _ , t := range template .Tasks {
528
534
t .FromRemote = true
@@ -535,8 +541,8 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
535
541
return true
536
542
}
537
543
538
- func (wi * WorkflowInclude ) Initialize (workflow * StackupWorkflow ) {
539
- wi .Workflow = workflow
544
+ func (wi * WorkflowInclude ) Initialize () {
545
+ // wi.Workflow = workflow
540
546
541
547
// expand environment variables in the include headers
542
548
for i , v := range wi .Headers {
0 commit comments