39 lines
653 B
Go
39 lines
653 B
Go
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
|
|
}
|