Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jaraco/keyring
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v25.1.0
Choose a base ref
...
head repository: jaraco/keyring
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v25.2.0
Choose a head ref

Commits on Apr 10, 2024

  1. Add link to blog entry from jaraco/skeleton#115 above CI build matrix.

    Bartosz Sławecki authored and jaraco committed Apr 10, 2024
    Copy the full SHA
    34ba6b2 View commit details

Commits on Apr 16, 2024

  1. Merge https://github.com/jaraco/skeleton

    jaraco committed Apr 16, 2024
    Copy the full SHA
    35a3a38 View commit details
  2. Copy the full SHA
    7ad4f2f View commit details
  3. Copy the full SHA
    0a104c8 View commit details
  4. Syntax

    BakerNet committed Apr 16, 2024
    Copy the full SHA
    95e4bb4 View commit details
  5. ruff

    BakerNet committed Apr 16, 2024
    Copy the full SHA
    9773fc4 View commit details
  6. fix _check_args

    BakerNet committed Apr 16, 2024
    Copy the full SHA
    8ee16b6 View commit details
  7. format

    BakerNet committed Apr 16, 2024
    Copy the full SHA
    9a2d951 View commit details
  8. Move project metadata to pyproject.toml (jaraco/skeleton#122)

    Intentionally omitted specifying `tool.setuptools.include-package-data`: it's true by default in `pyproject.toml` according to https://setuptools.pypa.io/en/latest/userguide/datafiles.html#include-package-data.
    
    Closes jaraco/skeleton#121
    Bartosz Sławecki authored Apr 16, 2024
    Copy the full SHA
    f4529af View commit details
  9. Copy the full SHA
    7830a64 View commit details
  10. Copy the full SHA
    bd1a7ca View commit details
  11. typos

    BakerNet committed Apr 16, 2024
    Copy the full SHA
    55432e9 View commit details

Commits on Apr 17, 2024

  1. change --get-mode to --mode

    BakerNet committed Apr 17, 2024
    Copy the full SHA
    1c6450a View commit details

Commits on Apr 18, 2024

  1. Migrated config to pyproject.toml using jaraco.develop.migrate-config…

    … and ini2toml.
    jaraco committed Apr 18, 2024
    Copy the full SHA
    f3adf64 View commit details

Commits on Apr 24, 2024

  1. Copy the full SHA
    744cf2a View commit details
  2. Move project.urls to appear in the order that ini2toml generates it. …

    …Remove project.scripts.
    jaraco committed Apr 24, 2024
    Copy the full SHA
    bcf8f07 View commit details
  3. Merge https://github.com/jaraco/skeleton

    # Conflicts:
    #	pyproject.toml
    jaraco committed Apr 24, 2024
    Copy the full SHA
    0ac3a11 View commit details

Commits on Apr 26, 2024

  1. Copy the full SHA
    98ce17a View commit details
  2. Copy the full SHA
    03801d7 View commit details
  3. Copy the full SHA
    734a17d View commit details
  4. Copy the full SHA
    f922be6 View commit details
  5. Rewrite _check_args using rules for required params. Consolidates log…

    …ic and reduces cyclomatic complexity to 2.
    jaraco committed Apr 26, 2024
    Copy the full SHA
    33bae95 View commit details
  6. Add news fragment.

    jaraco committed Apr 26, 2024
    Copy the full SHA
    49e7cf8 View commit details
  7. Merge pull request #678 from BakerNet/change/add-getcreds-to-cli

    feature: Add `get` options to cli for interface with `get_credential` and support JSON output
    jaraco authored Apr 26, 2024
    Copy the full SHA
    63dfe11 View commit details
  8. Finalize

    jaraco committed Apr 26, 2024
    Copy the full SHA
    f98adf3 View commit details
Showing with 145 additions and 77 deletions.
  1. +2 −1 .github/workflows/main.yml
  2. +9 −0 NEWS.rst
  3. +59 −6 keyring/cli.py
  4. +75 −1 pyproject.toml
  5. +0 −69 setup.cfg
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ env:
jobs:
test:
strategy:
# https://blog.jaraco.com/efficient-use-of-ci-resources/
matrix:
python:
- "3.8"
@@ -49,7 +50,7 @@ jobs:
- python: pypy3.10
platform: ubuntu-latest
runs-on: ${{ matrix.platform }}
continue-on-error: ${{ matrix.python == '3.13' }}
continue-on-error: ${{ matrix.python == '3.13' || (matrix.python == '3.8' || matrix.python == '3.9') && matrix.platform == 'macos-latest' }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
9 changes: 9 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v25.2.0
=======

Features
--------

- Added options for 'keyring get' command to support credential retrieval and emit as JSON. (#678)


v25.1.0
=======

65 changes: 59 additions & 6 deletions keyring/cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"""Simple command line interface to get/set password from a keyring"""

from __future__ import annotations

import argparse
import getpass
import json
import sys

from . import (
backend,
completion,
core,
credentials,
delete_password,
get_password,
set_keyring,
set_password,
get_credential,
)
from .util import platform_

@@ -41,6 +46,32 @@ def __init__(self):
self.parser.add_argument(
"--disable", action="store_true", help="Disable keyring and exit"
)
self.parser._get_modes = ["password", "creds"]
self.parser.add_argument(
"--mode",
choices=self.parser._get_modes,
dest="get_mode",
default="password",
help="""
Mode for 'get' operation.
'password' requires a username and will return only the password.
'creds' does not require a username and will return both the username and password separated by a newline.
Default is 'password'
""",
)
self.parser._output_formats = ["plain", "json"]
self.parser.add_argument(
"--output",
choices=self.parser._output_formats,
dest="output_format",
default="plain",
help="""
Output format for 'get' operation.
Default is 'plain'
""",
)
self.parser._operations = ["get", "set", "del", "diagnose"]
self.parser.add_argument(
'operation',
@@ -80,15 +111,37 @@ def run(self, argv):
return method()

def _check_args(self):
if self.operation:
if self.service is None or self.username is None:
self.parser.error(f"{self.operation} requires service and username")
needs_username = self.operation != 'get' or self.get_mode != 'creds'
required = (['service'] + ['username'] * needs_username) * bool(self.operation)
if any(getattr(self, param) is None for param in required):
self.parser.error(f"{self.operation} requires {' and '.join(required)}")

def do_get(self):
password = get_password(self.service, self.username)
if password is None:
credential = getattr(self, f'_get_{self.get_mode}')()
if credential is None:
raise SystemExit(1)
print(password)
getattr(self, f'_emit_{self.output_format}')(credential)

def _emit_json(self, credential: credentials.Credential):
print(
json.dumps(dict(username=credential.username, password=credential.password))
)

def _emit_plain(self, credential: credentials.Credential):
if credential.username:
print(credential.username)
print(credential.password)

def _get_cred(self) -> credentials.Credential | None:
return get_credential(self.service, self.username) # type: ignore

def _get_password(self) -> credentials.Credential | None:
password = get_password(self.service, self.username) # type: ignore
return (
credentials.SimpleCredential(None, password)
if password is not None
else None
)

def do_set(self):
password = self.input_password(
76 changes: 75 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,79 @@
[build-system]
requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"]
requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.1"]
build-backend = "setuptools.build_meta"

[project]
name = "keyring"
authors = [
{ name = "Kang Zhang", email = "jobo.zh@gmail.com" },
]
maintainers = [
{ name = "Jason R. Coombs", email = "jaraco@jaraco.com" },
]
description = "Store and access your passwords safely."
readme = "README.rst"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
]
requires-python = ">=3.8"
dependencies = [
'pywin32-ctypes>=0.2.0; sys_platform=="win32"',
'SecretStorage>=3.2; sys_platform=="linux"',
'jeepney>=0.4.2; sys_platform=="linux"',
'importlib_metadata >= 4.11.4; python_version < "3.12"',
"jaraco.classes",
'importlib_resources; python_version < "3.9"',
"jaraco.functools",
"jaraco.context",
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/jaraco/keyring"

[project.optional-dependencies]
testing = [
# upstream
"pytest >= 6, != 8.1.*",
"pytest-checkdocs >= 2.4",
"pytest-cov",
"pytest-mypy",
"pytest-enabler >= 2.2",
"pytest-ruff >= 0.2.1",

# local
]
docs = [
# upstream
"sphinx >= 3.5",
"jaraco.packaging >= 9.3",
"rst.linker >= 1.9",
"furo",
"sphinx-lint",

# tidelift
"jaraco.tidelift >= 1.4",

# local
]
completion = ["shtab >= 1.1.0"]

[project.entry-points]
devpi_client = {keyring = "keyring.devpi_client"}

[project.entry-points."keyring.backends"]
Windows = "keyring.backends.Windows"
macOS = "keyring.backends.macOS"
libsecret = "keyring.backends.libsecret"
SecretService = "keyring.backends.SecretService"
KWallet = "keyring.backends.kwallet"
chainer = "keyring.backends.chainer"

[project.scripts]
keyring = "keyring.cli:main"

[tool.setuptools_scm]
69 changes: 0 additions & 69 deletions setup.cfg

This file was deleted.