@@ -49,21 +49,22 @@ type WorkflowInclude struct {
4949 ValidationState string
5050 Contents string
5151 Hash string
52- Workflow * StackupWorkflow
52+ // Workflow *StackupWorkflow
5353}
5454
5555type WorkflowSettings struct {
5656 Defaults * WorkflowSettingsDefaults `yaml:"defaults"`
5757 ExitOnChecksumMismatch bool `yaml:"exit-on-checksum-mismatch"`
5858 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 {
6361 Allowed []string `yaml:"allowed"`
6462 } `yaml:"domains"`
6563}
6664
65+ type WorkflowSettingsCache struct {
66+ TtlMinutes int `yaml:"ttl-minutes"`
67+ }
6768type WorkflowSettingsDefaults struct {
6869 Tasks * WorkflowSettingsDefaultsTasks `yaml:"tasks"`
6970}
@@ -151,13 +152,13 @@ func (wi *WorkflowInclude) ValidateChecksum(contents string) (bool, error) {
151152 algorithm := ""
152153 storedChecksum := ""
153154 checksumContents := ""
154- hashUrl := ""
155155
156156 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)
161162 break
162163 }
163164
@@ -166,22 +167,27 @@ func (wi *WorkflowInclude) ValidateChecksum(contents string) (bool, error) {
166167 continue
167168 }
168169
170+ wi .ChecksumUrl = url
171+
169172 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)
173176 break
174177 }
175178 }
176179
177180 if checksumContents != "" {
178181 storedChecksum = wi .getChecksumFromContents (checksumContents )
179182
180- wi .ChecksumUrl = hashUrl
183+ // wi.ChecksumUrl = hashUrl
184+ // fmt.Println("checksum url: " + wi.ChecksumUrl)
181185 algorithm = wi .GetChecksumAlgorithm ()
182186 }
183187
184- if algorithm == "unknown" {
188+ // algorithm = "sha256"
189+
190+ if algorithm == "unknown" || algorithm == "" {
185191 return false , fmt .Errorf ("unable to find valid checksum file for %s" , wi .DisplayUrl ())
186192 }
187193
@@ -318,7 +324,7 @@ func (workflow *StackupWorkflow) reversePreconditions(items []*Precondition) []*
318324}
319325
320326func (workflow * StackupWorkflow ) Initialize () {
321- workflow .Cache = cache .CreateCache (utils . GetProjectName () )
327+ workflow .Cache = cache .CreateCache ("" )
322328
323329 // generate uuids for each task as the initial step, as other code below relies on a uuid existing
324330 for _ , task := range workflow .Tasks {
@@ -336,6 +342,7 @@ func (workflow *StackupWorkflow) Initialize() {
336342 if workflow .Settings == nil {
337343 workflow .Settings = & WorkflowSettings {
338344 DotEnvFiles : []string {".env" },
345+ Cache : & WorkflowSettingsCache {TtlMinutes : 5 },
339346 Defaults : & WorkflowSettingsDefaults {
340347 Tasks : & WorkflowSettingsDefaultsTasks {
341348 Silent : false ,
@@ -371,7 +378,7 @@ func (workflow *StackupWorkflow) Initialize() {
371378
372379 // initialize the includes
373380 for _ , inc := range workflow .Includes {
374- inc .Initialize (workflow )
381+ inc .Initialize ()
375382 }
376383
377384 workflow .ProcessIncludes ()
@@ -416,9 +423,9 @@ func (workflow *StackupWorkflow) ProcessIncludes() {
416423 var wg sync.WaitGroup
417424 for _ , include := range workflow .Includes {
418425 wg .Add (1 )
419- go func (include * WorkflowInclude ) {
426+ go func (inc * WorkflowInclude ) {
420427 defer wg .Done ()
421- workflow .ProcessInclude (include )
428+ workflow .ProcessInclude (inc )
422429 }(include )
423430 }
424431 wg .Wait ()
@@ -429,17 +436,16 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
429436 return false
430437 }
431438
432- var contents string
433439 var err error
434440
435441 if workflow .Cache .Has (include .DisplayName ()) && ! workflow .Cache .IsExpired (include .DisplayName ()) {
436442 include .Contents = workflow .Cache .Get (include .DisplayName ())
437443 include .Hash = workflow .Cache .GetHash (include .DisplayName ())
438- fmt .Println ("loaded from cache" )
444+ // fmt.Println("loaded from cache")
439445 }
440446
441447 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")
443449 if include .IsLocalFile () {
444450 include .Contents , err = utils .GetFileContents (include .Filename ())
445451 } else if include .IsRemoteUrl () {
@@ -453,7 +459,7 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
453459 }
454460
455461 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 )
457463 }
458464
459465 // fmt.Printf("value: %v\n", workflow.Cache.Get(include.DisplayName()))
@@ -473,8 +479,8 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
473479
474480 if include .IsRemoteUrl () {
475481 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 )
478484
479485 if include .ChecksumIsValid != nil && * include .ChecksumIsValid == true {
480486 include .ValidationState = "checksum validated"
@@ -484,10 +490,10 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
484490 include .ValidationState = "checksum mismatch"
485491 }
486492
487- if err != nil {
488- fmt .Println (err )
489- return false
490- }
493+ // if err != nil {
494+ // fmt.Println(err)
495+ // return false
496+ // }
491497
492498 if ! validated {
493499 if App .Workflow .Settings .ExitOnChecksumMismatch {
@@ -500,29 +506,29 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
500506 }
501507
502508 template := & IncludedTemplate {}
503- err = yaml .Unmarshal ([]byte (contents ), template )
509+ err = yaml .Unmarshal ([]byte (include . Contents ), template )
504510
505511 if err != nil {
506512 fmt .Println (err )
507513 return false
508514 }
509515
510516 if len (template .Init ) > 0 {
511- workflow .Init += "\n " + template .Init
517+ App . Workflow .Init += "\n " + template .Init
512518 }
513519
514520 // prepend the included preconditions; we reverse the order of the preconditions in the included file,
515521 // then reverse the existing preconditions, append them, then reverse the workflow preconditions again
516522 // 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 )
519525
520526 for _ , p := range template .Preconditions {
521527 p .FromRemote = true
522528 App .Workflow .Preconditions = append (App .Workflow .Preconditions , p )
523529 }
524530
525- App .Workflow .Preconditions = workflow .reversePreconditions (App .Workflow .Preconditions )
531+ App .Workflow .Preconditions = App . Workflow .reversePreconditions (App .Workflow .Preconditions )
526532
527533 for _ , t := range template .Tasks {
528534 t .FromRemote = true
@@ -535,8 +541,8 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
535541 return true
536542}
537543
538- func (wi * WorkflowInclude ) Initialize (workflow * StackupWorkflow ) {
539- wi .Workflow = workflow
544+ func (wi * WorkflowInclude ) Initialize () {
545+ // wi.Workflow = workflow
540546
541547 // expand environment variables in the include headers
542548 for i , v := range wi .Headers {
0 commit comments