amo/api/secret.go

40 lines
653 B
Go
Raw Normal View History

2024-05-30 11:43:10 +03:00
package api
import "encoding/json"
import "os"
import "io"
func (api *Client) readSecret() (ClientOptions, error) {
f, err := os.Open(api.secretStoreFilePath)
if err != nil {
return ClientOptions{}, err
}
bts, err := io.ReadAll(f)
if err != nil {
return ClientOptions{}, err
}
ret := ClientOptions{}
err = json.Unmarshal(bts, &ret)
if err != nil {
return ClientOptions{}, err
}
return ret, nil
}
func (api *Client) writeSecret() error {
bts, err := json.MarshalIndent(api.options, "", "\t")
if err != nil {
return err
}
err = os.WriteFile(api.secretStoreFilePath, bts, 0644)
if err != nil {
return err
}
return err
}