forked from kramphub/kiya
/
cmd_move.go
31 lines (27 loc) · 890 Bytes
/
cmd_move.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"fmt"
"log"
cloudstore "cloud.google.com/go/storage"
"github.com/emicklei/tre"
cloudkms "google.golang.org/api/cloudkms/v1"
)
// commandMove transfers a secret from a source to a target profile.
func commandMove(
kmsService *cloudkms.Service,
storageService *cloudstore.Client,
source profile,
sourceKey string,
target profile,
targetKey string) {
// fetch value for key from source
sourceValue, err := getValueByKey(kmsService, storageService, sourceKey, source)
if err != nil {
log.Fatal(tre.New(err, "get source key failed", "key", sourceKey))
}
// store value for key to target
commandPutPasteGenerate(kmsService, storageService, target, "put", targetKey, sourceValue, true)
fmt.Printf("Successfully copied [%s] to [%s]\n", sourceKey, target.Label)
// delete key from source
commandDelete(kmsService, storageService, source, sourceKey)
}