(ctx ssh.Context, filteredHosts []nix.Host, phase *string)
| 699 | } |
| 700 | |
| 701 | func secretsUpload(ctx ssh.Context, filteredHosts []nix.Host, phase *string) error { |
| 702 | // upload secrets |
| 703 | // relative paths are resolved relative to the deployment file (!) |
| 704 | deploymentDir := filepath.Dir(deployment) |
| 705 | for _, host := range filteredHosts { |
| 706 | fmt.Fprintf(os.Stderr, "Uploading secrets to %s (%s):\n", host.Name, host.TargetHost) |
| 707 | postUploadActions := make(map[string][]string, 0) |
| 708 | for secretName, secret := range host.Secrets { |
| 709 | // if phase is nil, upload the secrets no matter what phase it wants |
| 710 | // if phase is non-nil, upload the secrets that match the specified phase |
| 711 | if phase != nil && secret.UploadAt != *phase { |
| 712 | continue |
| 713 | } |
| 714 | |
| 715 | secretSize, err := secrets.GetSecretSize(secret, deploymentDir) |
| 716 | if err != nil { |
| 717 | return err |
| 718 | } |
| 719 | |
| 720 | secretErr := secrets.UploadSecret(ctx, &host, secret, deploymentDir) |
| 721 | fmt.Fprintf(os.Stderr, "\t* %s (%d bytes).. ", secretName, secretSize) |
| 722 | if secretErr != nil { |
| 723 | if secretErr.Fatal { |
| 724 | fmt.Fprintln(os.Stderr, "Failed") |
| 725 | return secretErr |
| 726 | } else { |
| 727 | fmt.Fprintln(os.Stderr, "Partial") |
| 728 | fmt.Fprint(os.Stderr, secretErr.Error()) |
| 729 | } |
| 730 | } else { |
| 731 | fmt.Fprintln(os.Stderr, "OK") |
| 732 | } |
| 733 | if len(secret.Action) > 0 { |
| 734 | // ensure each action is only run once |
| 735 | postUploadActions[strings.Join(secret.Action, " ")] = secret.Action |
| 736 | } |
| 737 | } |
| 738 | // Execute post-upload secret actions one-by-one after all secrets have been uploaded |
| 739 | for _, action := range postUploadActions { |
| 740 | fmt.Fprintf(os.Stderr, "\t- executing post-upload command: "+strings.Join(action, " ")+"\n") |
| 741 | // Errors from secret actions will be printed on screen, but we won't stop the flow if they fail |
| 742 | ctx.CmdInteractive(&host, timeout, action...) |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return nil |
| 747 | } |
| 748 | |
| 749 | func activateConfiguration(ctx ssh.Context, filteredHosts []nix.Host, resultPath string) error { |
| 750 | fmt.Fprintln(os.Stderr, "Executing '"+deploySwitchAction+"' on matched hosts:") |
no test coverage detected