forked from XeroAPI/xoauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.go
43 lines (31 loc) · 888 Bytes
/
secret.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
32
33
34
35
36
37
38
39
40
41
42
43
package config
import (
"errors"
"log"
"github.com/NathanBeddoeWebDev/xoauth/pkg/db"
"github.com/spf13/cobra"
)
func ValidateSecretCmdArgs(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please supply a client name, e.g, `xero`")
}
if len(args) < 2 {
return errors.New("please supply a client secret, e.g, `secret`")
}
return nil
}
func UpdateSecret(database *db.CredentialStore, clientName string, clientSecret string) {
allClients, clientsErr := database.GetClients()
if clientsErr != nil {
log.Fatal(clientsErr)
}
client, clientErr := database.GetClientWithoutSecret(allClients, clientName)
if clientErr != nil {
log.Fatal(clientErr)
}
_, secretErr := database.SetClientSecret(client.Alias, clientSecret)
if secretErr != nil {
log.Fatal(secretErr)
}
log.Printf("Updated client secret for %s\n", client.Alias)
}