From 159e3819940075651cd966e6106f1a143bcaa364 Mon Sep 17 00:00:00 2001 From: simulot Date: Mon, 1 Apr 2024 22:37:36 +0200 Subject: [PATCH] immich-go appears to retain/cache an API key Fixes #211 --- cmd/shared.go | 24 ++++++++++++++---------- docs/releases.md | 16 ++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/shared.go b/cmd/shared.go index 5352eb4..ac07139 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -105,12 +105,14 @@ func (app *SharedFlags) Start(ctx context.Context) error { // If the client isn't yet initialized if app.Immich == nil { - conf, err := configuration.Read(app.ConfigurationFile) - confExist := err == nil - if confExist && app.Server == "" && app.Key == "" && app.API == "" { - app.Server = conf.ServerURL - app.Key = conf.APIKey - app.API = conf.APIURL + if app.Server == "" && app.API == "" && app.Key == "" { + conf, err := configuration.Read(app.ConfigurationFile) + confExist := err == nil + if confExist && app.Server == "" && app.Key == "" && app.API == "" { + app.Server = conf.ServerURL + app.Key = conf.APIKey + app.API = conf.APIURL + } } switch { @@ -125,10 +127,12 @@ func (app *SharedFlags) Start(ctx context.Context) error { } // Connection details are saved into the configuration file - conf.ServerURL = app.Server - conf.APIKey = app.Key - conf.APIURL = app.API - err = conf.Write(app.ConfigurationFile) + conf := configuration.Configuration{ + ServerURL: app.Server, + APIKey: app.Key, + APIURL: app.API, + } + err := conf.Write(app.ConfigurationFile) if err != nil { err = fmt.Errorf("can't write into the configuration file: %w", err) joinedErr = errors.Join(joinedErr, err) diff --git a/docs/releases.md b/docs/releases.md index 72d41f6..efb724c 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -1,17 +1,13 @@ # Release notes -## Release 0.13.1 - -### Improvement: [#195](https://github.com/simulot/immich-go/issues/195) Rethink the user interactions with the CLI application #195 - -#### Use Bubble Tea library to provide a modern TUI (Terminal User Interface) - - -### API KEY self provisioning -When the server and the API keys aren't given on the command line, immich-go ask the user if he wants to get a key from a server, and saves it the configuration file. +## Release 0.13.0 -### Fix [#199](https://github.com/simulot/immich-go/issues/199) +### Fix [[#211](https://github.com/simulot/immich-go/issues/211)] immich-go appears to retain/cache an API key +Fix the logic for retaining the credential: +When given, the credentials are saved into the configuration file. +When not given, the credential are read from the configuration file if possible. + ## Release 0.13.0 ### Improvement: [#189](https://github.com/simulot/immich-go/issues/189) Use a configuration file to store server's address and its API key