Skip to content

feat: add support for token storage in encrypted keyrings

Marek Vospěl requested to merge (removed):feat-keyring-support into main

Description

This MR adds system keyring support trough zalando/go-keyring library. The way this is implemented is if no token is found in the host config, glab cli tries to load the value for that hostname from the keyring (prefixed with "glab:", so it doesn't conflict with other apps) For logging in I've added the --use-keyring flag, which works for both --stdin (or --token) arguments and for values loaded trough the login survey. For loading the token I have ignored the errors, as if there is an error it either is because the value doesn't exist in the keyring, or the keyring isn't setup, with which we don't want to bother users, as it likely is intentional.

The tokens are stored in the config by default, which we might want to change in the future, but at least for temporary testing purposes I think this makes sense. https://gitlab.com/marekvospel/glab/-/commit/c5f06fd679e3abeb53673fe9172ff72e374fceda#5aa04c368755769a6e46987a8a1f6c982200eb0f_102_105

Note this MR was inspired by a github cli implementation, but only to the point, where it can be considered fair use.

Related Issues

Resolves #957 (closed)

How has this been tested?

zalando/go-keyring supports mocking the keychain, so I have added tests for both setting and loading values from it trough the login command and in config loading tests, I have also added inputs for the Test_NewCmdLogin for the --use-keyring argument I added.

Affected tests

  • commands/auth/login/login_test.go: Test_NewCmdLogin
  • commands/auth/login/login_test.go: Test_keyringLogin (Added)
  • internal/config/config_type_test.go: Test_getFromKeyring (Added)

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)
  • Test gap
Edited by Marek Vospěl

Merge request reports