mirror of https://github.com/databricks/cli.git
add new write function to persist to disk
This commit is contained in:
parent
89d3b1a4df
commit
d037ec32a1
|
@ -52,11 +52,7 @@ func (c *FileTokenCache) Store(key string, t *oauth2.Token) error {
|
||||||
c.Tokens = map[string]*oauth2.Token{}
|
c.Tokens = map[string]*oauth2.Token{}
|
||||||
}
|
}
|
||||||
c.Tokens[key] = t
|
c.Tokens[key] = t
|
||||||
raw, err := json.MarshalIndent(c, "", " ")
|
return c.write()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("marshal: %w", err)
|
|
||||||
}
|
|
||||||
return os.WriteFile(c.fileLocation, raw, ownerReadWrite)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FileTokenCache) Lookup(key string) (*oauth2.Token, error) {
|
func (c *FileTokenCache) Lookup(key string) (*oauth2.Token, error) {
|
||||||
|
@ -88,11 +84,7 @@ func (c *FileTokenCache) Delete(key string) error {
|
||||||
return ErrNotConfigured
|
return ErrNotConfigured
|
||||||
}
|
}
|
||||||
delete(c.Tokens, key)
|
delete(c.Tokens, key)
|
||||||
raw, err := json.MarshalIndent(c, "", " ")
|
return c.write()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("marshal: %w", err)
|
|
||||||
}
|
|
||||||
return os.WriteFile(c.fileLocation, raw, ownerReadWrite)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FileTokenCache) location() (string, error) {
|
func (c *FileTokenCache) location() (string, error) {
|
||||||
|
@ -127,4 +119,12 @@ func (c *FileTokenCache) load() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FileTokenCache) write() error {
|
||||||
|
raw, err := json.MarshalIndent(c, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshal: %w", err)
|
||||||
|
}
|
||||||
|
return os.WriteFile(c.fileLocation, raw, ownerReadWrite)
|
||||||
|
}
|
||||||
|
|
||||||
var _ TokenCache = (*FileTokenCache)(nil)
|
var _ TokenCache = (*FileTokenCache)(nil)
|
||||||
|
|
Loading…
Reference in New Issue