Skip to content

Commit 8ec46ba

Browse files
committed
finalize remote includes
1 parent a6f25ea commit 8ec46ba

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/app/workflow.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ func (wi *WorkflowInclude) ValidateChecksum(contents string) (bool, error) {
164164
return false, fmt.Errorf("unsupported algorithm: %s", algorithm)
165165
}
166166

167-
fmt.Printf("checksum url: %s\n", wi.ChecksumUrl)
168-
fmt.Printf("algorithm: %s\n", algorithm)
169-
fmt.Printf("hash: %x\n", hash)
170-
fmt.Printf("checksum: %s\n", checksumContents)
167+
// fmt.Printf("checksum url: %s\n", wi.ChecksumUrl)
168+
// fmt.Printf("algorithm: %s\n", algorithm)
169+
// fmt.Printf("hash: %x\n", hash)
170+
// fmt.Printf("checksum: %s\n", checksumContents)
171171

172172
checksumBytes, err := hex.DecodeString(string(checksumContents))
173173
if err != nil {
@@ -226,6 +226,15 @@ func (workflow *StackupWorkflow) TaskIdToUuid(id string) string {
226226
return task.Uuid
227227
}
228228

229+
func (workflow *StackupWorkflow) reversePreconditions(items []*Precondition) []*Precondition {
230+
length := len(items)
231+
for i := 0; i < length/2; i++ {
232+
items[i], items[length-i-1] = items[length-i-1], items[i]
233+
}
234+
235+
return items
236+
}
237+
229238
func (workflow *StackupWorkflow) Initialize() {
230239
// generate uuids for each task as the initial step, as other code below relies on a uuid existing
231240
for _, task := range workflow.Tasks {
@@ -323,6 +332,8 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
323332

324333
contents, err := utils.GetUrlContents(include.FullUrl())
325334

335+
fmt.Println("contents: ", contents)
336+
326337
if err != nil {
327338
fmt.Println(err)
328339
return false
@@ -363,13 +374,22 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
363374
workflow.Init += "\n\n" + template.Init
364375
}
365376

377+
// prepend the included preconditions; we reverse the order of the preconditions in the included file,
378+
// then reverse the existing preconditions, append them, then reverse the workflow preconditions again
379+
// to achieve the correct order.
380+
App.Workflow.Preconditions = workflow.reversePreconditions(App.Workflow.Preconditions)
381+
template.Preconditions = workflow.reversePreconditions(template.Preconditions)
382+
366383
for _, p := range template.Preconditions {
367384
p.FromRemote = true
368385
App.Workflow.Preconditions = append(App.Workflow.Preconditions, p)
369386
}
370387

388+
App.Workflow.Preconditions = workflow.reversePreconditions(App.Workflow.Preconditions)
389+
371390
for _, t := range template.Tasks {
372391
t.FromRemote = true
392+
t.Uuid = utils.GenerateTaskUuid()
373393
App.Workflow.Tasks = append(App.Workflow.Tasks, t)
374394
}
375395

lib/utils/utils.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func FindFirstExistingFile(filenames []string) (string, error) {
120120
}
121121

122122
func GetUrlContents(url string) (string, error) {
123-
resp, err := http.Get(url)
123+
resp, err := http.Get(url + "?nocache=" + GenerateShortID(8))
124124
if err != nil {
125125
return "", err
126126
}
@@ -247,3 +247,11 @@ func CalculateSHA256Hash(input string) string {
247247

248248
return strings.ToLower(hashString)
249249
}
250+
251+
func ReverseStructArray(arr []*interface{}) any {
252+
length := len(arr)
253+
for i := 0; i < length/2; i++ {
254+
arr[i], arr[length-i-1] = arr[length-i-1], arr[i]
255+
}
256+
return arr
257+
}

0 commit comments

Comments
 (0)