Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
z0rr0 committed Jul 30, 2023
1 parent 0a8e4f3 commit d8adbfb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ type Token struct {
func (a *Account) loadPrivateKey() (*rsa.PrivateKey, error) {
data, err := os.ReadFile(a.KeyFile)
if err != nil {
return nil, err
return nil, fmt.Errorf("read key file: %w", err)
}
rsaPrivateKey, err := jwt.ParseRSAPrivateKeyFromPEM(data)
if err != nil {
return nil, err
return nil, fmt.Errorf("parse key file: %w", err)
}
return rsaPrivateKey, nil
}
Expand Down
4 changes: 2 additions & 2 deletions config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Cache struct {
// readCachedToken reads cached token from file.
func readCachedToken(fileName string) (string, error) {
if fileName == "" {
return "", nil
return "", nil // no file name, no cache
}
data, err := os.ReadFile(fileName)
if err != nil {
Expand Down Expand Up @@ -48,7 +48,7 @@ func readCachedToken(fileName string) (string, error) {
// writeCachedToken writes token to a cache file.
func writeCachedToken(fileName, token string, expiresAt time.Time) error {
if fileName == "" {
return nil // no cache
return nil // no file name, no cache
}

cache := &Cache{Token: token, Expired: expiresAt.Format(time.DateTime)}
Expand Down
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func New(fileName, configDir, cacheDir string, noCache, debug bool, logger *log.
}

func (c *Config) setLogger(logger *log.Logger, debug bool) {
c.Lock()
defer c.Unlock()

if debug || c.Debug {
logger.SetOutput(os.Stdout)
}
Expand All @@ -72,6 +75,9 @@ func (c *Config) setLogger(logger *log.Logger, debug bool) {

// setFiles sets paths for key file and auth cache.
func (c *Config) setFiles(configDir, cacheDir string) error {
c.Lock()
defer c.Unlock()

if !filepath.IsAbs(c.Translation.KeyFile) {
c.Translation.KeyFile = filepath.Join(configDir, c.Translation.KeyFile)
}
Expand Down Expand Up @@ -102,6 +108,9 @@ func (c *Config) setFiles(configDir, cacheDir string) error {

// setProxy sets HTTP proxy or uses environment variables.
func (c *Config) setProxy() error {
c.Lock()
defer c.Unlock()

if c.ProxyURL != "" {
u, err := url.Parse(c.ProxyURL)

Expand Down

0 comments on commit d8adbfb

Please sign in to comment.