@@ -121,11 +121,11 @@ func (i AppInfo) ValidateName() error {
121121// If no key credential could be found, a Client is returned that can only be used for unauthenticated routes.
122122func NewClient (with ... ClientOption ) (* Client , error ) {
123123 client := & Client {
124- httpClient : http .NewClient (),
125- repoIndexKeys : make (map [api.RepoPath ]* crypto.SymmetricKey ),
126- appInfo : []* AppInfo {},
127- defaultPassphraseReader : credentials .FromEnv ("SECRETHUB_CREDENTIAL_PASSPHRASE" ),
124+ httpClient : http .NewClient (),
125+ repoIndexKeys : make (map [api.RepoPath ]* crypto.SymmetricKey ),
126+ appInfo : []* AppInfo {},
128127 }
128+
129129 err := client .with (with ... )
130130 if err != nil {
131131 return nil , err
@@ -157,26 +157,12 @@ func NewClient(with ...ClientOption) (*Client, error) {
157157 }
158158
159159 err := client .with (WithCredentials (provider ))
160- // nolint: staticcheck
161160 if err != nil {
162- // TODO: log that default credential was not loaded.
163- // Do go on because we want to allow an unauthenticated client.
164- }
165- }
166-
167- appName := os .Getenv ("SECRETHUB_APP_INFO_NAME" )
168- if appName != "" {
169- appVersion := os .Getenv ("SECRETHUB_APP_INFO_VERSION" )
170- topLevelAppInfo := & AppInfo {
171- Name : appName ,
172- Version : appVersion ,
173- }
174- // Ignore app info from environment variable if name is invalid
175- if err = topLevelAppInfo .ValidateName (); err == nil {
176- client .appInfo = append (client .appInfo , topLevelAppInfo )
161+ return nil , err
177162 }
178163 }
179164
165+ client .loadAppInfoFromEnv ()
180166 userAgent := client .userAgent ()
181167
182168 client .httpClient .Options (http .WithUserAgent (userAgent ))
@@ -288,6 +274,21 @@ func (c *Client) isKeyed() bool {
288274 return c .decrypter != nil
289275}
290276
277+ func (c * Client ) loadAppInfoFromEnv () {
278+ appName := os .Getenv ("SECRETHUB_APP_INFO_NAME" )
279+ if appName != "" {
280+ appVersion := os .Getenv ("SECRETHUB_APP_INFO_VERSION" )
281+ topLevelAppInfo := & AppInfo {
282+ Name : appName ,
283+ Version : appVersion ,
284+ }
285+ // Ignore app info from environment variable if name is invalid
286+ if err := topLevelAppInfo .ValidateName (); err == nil {
287+ c .appInfo = append (c .appInfo , topLevelAppInfo )
288+ }
289+ }
290+ }
291+
291292func (c * Client ) userAgent () string {
292293 userAgent := userAgentPrefix
293294 for _ , info := range c .appInfo {
0 commit comments