Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "--reset-credentials" argument #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openconnect_sso/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def configure_logger(logger, level):


async def _run(args, cfg):
if args.reset_credentials:
del Credentials(args.user).password
del Credentials(args.user).totp

credentials = None
if cfg.credentials:
credentials = cfg.credentials
Expand Down
7 changes: 7 additions & 0 deletions openconnect_sso/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def create_argparser():
credentials_group.add_argument(
"-u", "--user", help="Authenticate as the given user", default=None
)
credentials_group.add_argument(
"--reset-credentials",
dest="reset_credentials",
help="Delete saved credentials from keyring",
action="store_true",
default=False
)
return parser


Expand Down
16 changes: 16 additions & 0 deletions openconnect_sso/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def password(self, value):
keyring.set_password(APP_NAME, self.username, value)
except keyring.errors.KeyringError:
logger.info("Cannot save password to keyring.")

@password.deleter
def password(self):
try:
return keyring.delete_password(APP_NAME, self.username)
except keyring.errors.KeyringError:
logger.info("Cannot delete saved password from keyring.")
return ""

@property
def totp(self):
Expand All @@ -138,6 +146,14 @@ def totp(self, value):
except keyring.errors.KeyringError:
logger.info("Cannot save totp secret to keyring.")

@totp.deleter
def totp(self):
try:
return keyring.delete_password(APP_NAME, "totp/" + self.username)
except keyring.errors.KeyringError:
logger.info("Cannot delete saved totp secret from keyring.")
return ""


@attr.s
class Config(ConfigNode):
Expand Down