Skip to content

Commit

Permalink
Syntax and test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfioravanti committed Sep 22, 2024
1 parent 126246c commit 7d58236
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 40 deletions.
3 changes: 2 additions & 1 deletion plover_1password/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
A package dealing with:
- retrieving secrets from 1Password and outputting them
"""
from .__version__ import __version__

__all__ = [
"__version__"
]

from .__version__ import __version__
3 changes: 2 additions & 1 deletion plover_1password/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Version attribute
"""
__version__ = "0.3.11"

__version__ = "0.3.12"
2 changes: 2 additions & 0 deletions plover_1password/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- https://plover.readthedocs.io/en/latest/plugin-dev/extensions.html
- https://plover.readthedocs.io/en/latest/plugin-dev/meta.html
"""

import asyncio
import platform
from typing import Callable
Expand All @@ -30,6 +31,7 @@ class OnePassword:
Extension class that also registers a meta plugin.
The meta deals with retrieving secrets from 1Password
"""

_client: Client
_engine: StenoEngine
_platform: str
Expand Down
5 changes: 3 additions & 2 deletions plover_1password/secret/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
A package dealing with:
- retrieving and resolving a secret from a 1Password vault
"""
from .client import init_client
from .resolver import resolve

__all__ = [
"init_client",
"resolve"
]

from .client import init_client
from .resolver import resolve
1 change: 1 addition & 0 deletions plover_1password/secret/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module to initialise a 1Password client
"""

from onepassword.client import Client

from ..__version__ import __version__
Expand Down
1 change: 1 addition & 0 deletions plover_1password/secret/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
but not handled in the Python SDK.
See: https://github.com/1Password/onepassword-sdk-python/tree/main/src/onepassword/lib
"""

_SERVICE_ACCOUNT_TOKEN_INVALID_ERROR: str = (
"invalid service account token, please make sure you provide a valid "
"service account token as parameter: service account deserialization "
Expand Down
1 change: 1 addition & 0 deletions plover_1password/secret/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module to resolve a given 1Password secret reference URI to a secret contained
in a vault.
"""

from onepassword.client import Client

from . import error
Expand Down
3 changes: 2 additions & 1 deletion plover_1password/secret_reference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
A package dealing with:
- expanding local environment variables within a secret reference URI
"""
from .expander import expand_env_vars

__all__ = [
"expand_env_vars"
]

from .expander import expand_env_vars
1 change: 1 addition & 0 deletions plover_1password/secret_reference/expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Expander - a module for dealing with expansion of ENV vars in a secret
reference URI.
"""

import os
from typing import Callable

Expand Down
4 changes: 2 additions & 2 deletions plover_1password/service_account/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
functionality
"""

from .token import get_token

__all__ = [
"get_token"
]

from .token import get_token
1 change: 1 addition & 0 deletions plover_1password/service_account/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Token - Module concerning retrieving a token value for a 1Password Service
Account
"""

import os
from typing import (
Callable,
Expand Down
3 changes: 2 additions & 1 deletion plover_1password/shell_command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
A package dealing with:
- resolve the platform-appropriate command to fetch environment variables
"""
from .resolver import resolve

__all__ = [
"resolve"
]

from .resolver import resolve
1 change: 1 addition & 0 deletions plover_1password/shell_command/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Resolver - a module for resolving the platform-appropriate command to fetch
environment variables.
"""

import os
from typing import Callable

Expand Down
28 changes: 28 additions & 0 deletions test/secret/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest


@pytest.fixture()
def mock_client(mocker):
async_mock = mocker.AsyncMock()
mocker.patch(
"onepassword.client.Client.authenticate",
return_value=async_mock
)

# REF: https://stackoverflow.com/a/8294654/567863
def raise_(exc):
raise exc

# REF: https://stackoverflow.com/a/44701916/567863
def _method(error_message="", return_value=None):
if error_message:
async_mock.secrets.resolve.side_effect = (
lambda _return_value: raise_(Exception(error_message))
)

if return_value:
async_mock.secrets.resolve.return_value = return_value

return async_mock

return _method
26 changes: 0 additions & 26 deletions test/secret/test_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,6 @@
from plover_1password import secret


@pytest.fixture()
def mock_client(mocker):
async_mock = mocker.AsyncMock()
mocker.patch(
"onepassword.client.Client.authenticate",
return_value=async_mock
)

# REF: https://stackoverflow.com/a/8294654/567863
def raise_(exc):
raise exc

# REF: https://stackoverflow.com/a/44701916/567863
def _method(error_message="", return_value=None):
if error_message:
async_mock.secrets.resolve.side_effect = (
lambda _return_value: raise_(Exception(error_message))
)

if return_value:
async_mock.secrets.resolve.return_value = return_value

return async_mock

return _method

async def test_initialising_a_client(mock_client):
assert await secret.init_client("service_account_token") == mock_client()

Expand Down
9 changes: 9 additions & 0 deletions test/shell_command/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest


@pytest.fixture()
def bash_command():
def _method(shell):
return lambda env_var: f"{shell} -ic 'echo {env_var}'"

return _method
6 changes: 0 additions & 6 deletions test/shell_command/test_shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

from plover_1password import shell_command

@pytest.fixture()
def bash_command():
def _method(shell):
return lambda env_var: f"{shell} -ic 'echo {env_var}'"

return _method

def test_resolve_shell_command_for_windows(powershell_command):
# REF: https://stackoverflow.com/a/20059029/567863
Expand Down

0 comments on commit 7d58236

Please sign in to comment.