Skip to content

Commit 7ea141c

Browse files
committed
Merge branch 'main' of github.com:Shuffle/Shuffle-shared
2 parents fabc4cd + 9f7d811 commit 7ea141c

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

cloudSync.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,15 @@ func SetGitWorkflow(ctx context.Context, workflow Workflow, org *Org) error {
806806

807807
// FIXME: Decrypt here
808808
if workflow.BackupConfig.TokensEncrypted {
809-
log.Printf("\n\n[DEBUG] Should realtime decrypt token for org %s (%s)\n\n", org.Name, org.Id)
809+
log.Printf("[DEBUG] Should realtime decrypt token for org %s (%s)", org.Name, org.Id)
810810
org.Defaults.TokensEncrypted = true
811811
} else {
812812
org.Defaults.TokensEncrypted = false
813813
}
814814
}
815815

816816
if org.Defaults.TokensEncrypted == true {
817-
log.Printf("\n\n[DEBUG] Decrypting token for org %s (%s)\n\n", org.Name, org.Id)
817+
log.Printf("[DEBUG] Decrypting token for org %s (%s)", org.Name, org.Id)
818818

819819
parsedKey := fmt.Sprintf("%s_upload_token", org.Id)
820820
newValue, err := HandleKeyDecryption([]byte(org.Defaults.WorkflowUploadToken), parsedKey)
@@ -894,9 +894,11 @@ func SetGitWorkflow(ctx context.Context, workflow Workflow, org *Org) error {
894894
}
895895

896896
commitMessage := fmt.Sprintf("User '%s' updated workflow '%s' with status '%s'", workflow.UpdatedBy, workflow.Name, workflow.Status)
897-
location := fmt.Sprintf("https://%s:%s@%s.git", org.Defaults.WorkflowUploadUsername, org.Defaults.WorkflowUploadToken, org.Defaults.WorkflowUploadRepo)
897+
urlEncodedPassword := url.QueryEscape(org.Defaults.WorkflowUploadToken)
898+
location := fmt.Sprintf("https://%s:%s@%s.git", org.Defaults.WorkflowUploadUsername, urlEncodedPassword, org.Defaults.WorkflowUploadRepo)
898899

899-
log.Printf("[DEBUG] Uploading workflow %s to repo: %s", workflow.ID, strings.Replace(location, org.Defaults.WorkflowUploadToken, "****", -1))
900+
newRepoName := strings.Replace(strings.Replace(location, org.Defaults.WorkflowUploadToken, "****", -1), urlEncodedPassword, "****", -1)
901+
log.Printf("[DEBUG] Uploading workflow %s to repo: %s", workflow.ID, newRepoName)
900902

901903
fs := memfs.New()
902904
if len(workflow.Status) == 0 {
@@ -910,40 +912,48 @@ func SetGitWorkflow(ctx context.Context, workflow Workflow, org *Org) error {
910912
repo, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
911913
URL: location,
912914
})
913-
914-
// Initialize a new Git repository in memory
915-
w := &git.Worktree{}
916915
if err != nil {
917-
log.Printf("[ERROR] Error cloning repo (workflow backup): %s", err)
916+
newErr := strings.ReplaceAll(err.Error(), org.Defaults.WorkflowUploadToken, "****")
917+
newErr = strings.ReplaceAll(newErr, urlEncodedPassword, "****")
918+
919+
log.Printf("[ERROR] Error cloning repo '%s' (workflow backup): %s", newRepoName, newErr)
918920
return err
919921
}
920922

923+
// Initialize a new Git repository in memory
924+
w := &git.Worktree{}
925+
921926
// Create a new commit with the in-memory file
922927
w, err = repo.Worktree()
923928
if err != nil {
924-
log.Printf("[ERROR] Error getting worktree (2): %s", err)
929+
newErr := strings.ReplaceAll(err.Error(), org.Defaults.WorkflowUploadToken, "****")
930+
newErr = strings.ReplaceAll(newErr, urlEncodedPassword, "****")
931+
932+
log.Printf("[ERROR] Error getting worktree for repo '%s' (2): %s", newRepoName, newErr)
925933
return err
926934
}
927935

928936
// Write the byte blob to the in-memory file system
929937
file, err := fs.Create(filePath)
930938
if err != nil {
931-
log.Printf("[ERROR] Creating file: %v", err)
939+
newErr := strings.ReplaceAll(err.Error(), org.Defaults.WorkflowUploadToken, "****")
940+
941+
log.Printf("[ERROR] Creating git file: %v", newErr)
932942
return err
933943
}
934944

935945
defer file.Close()
936946
//_, err = io.Copy(file, bytes.NewReader(workflowData))
937947
_, err = io.Copy(file, bytes.NewReader(workflowData))
938948
if err != nil {
939-
log.Printf("[ERROR] Writing data to file: %v", err)
949+
log.Printf("[ERROR] Writing data to git file: %v", err)
940950
return err
941951
}
942952

943953
// Add the file to the staging area
944954
_, err = w.Add(filePath)
945955
if err != nil {
946-
log.Printf("[ERROR] Error adding file to staging area (2): %s", err)
956+
log.Printf("[ERROR] Error adding file to git staging area (2): %s", err)
947957
return err
948958
}
949959

@@ -956,7 +966,7 @@ func SetGitWorkflow(ctx context.Context, workflow Workflow, org *Org) error {
956966
},
957967
})
958968
if err != nil {
959-
log.Printf("[ERROR] Committing changes: %v (2)", err)
969+
log.Printf("[ERROR] Committing git changes: %v (2)", err)
960970
return err
961971
}
962972

@@ -971,11 +981,11 @@ func SetGitWorkflow(ctx context.Context, workflow Workflow, org *Org) error {
971981
RemoteURL: location,
972982
})
973983
if err != nil {
974-
log.Printf("[ERROR] Change Push issue: %v (2)", err)
984+
log.Printf("[ERROR] Change git Push issue: %v (2)", err)
975985
return err
976986
}
977987

978-
log.Println("[DEBUG] File uploaded successfully!")
988+
log.Printf("[DEBUG] File uploaded successfully to '%s'!", newRepoName)
979989

980990

981991

0 commit comments

Comments
 (0)