/
token.go
50 lines (40 loc) · 960 Bytes
/
token.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
44
45
46
47
48
49
50
package internal
import (
"encoding/json"
"io/ioutil"
)
// TokenSource object to save in file
type TokenSource struct {
Source string `json:"source"`
Token string `json:"token"`
}
// TokenSources multiple TokenSource
type TokenSources []TokenSource
// TerraformToken JSON token object
type TerraformToken struct {
Token string `json:"token"`
}
// JSON return current token instance as JSON bytes
func (t *TerraformToken) JSON() string {
s, err := json.MarshalIndent(t, "", " ")
if err != nil {
panic(err)
}
return string(s)
}
// JSON return current token instance as JSON bytes
func (t *TokenSources) JSON() string {
s, err := json.MarshalIndent(t, "", " ")
if err != nil {
panic(err)
}
return string(s)
}
// WriteToFile write tokens to given file
func (t *TokenSources) WriteToFile(filepath string) error {
d, err := json.MarshalIndent(t, "", " ")
if err != nil {
return err
}
return ioutil.WriteFile(filepath, d, 0644)
}