Skip to content

Commit

Permalink
feat(configuration): make max batch results configurable (#11)
Browse files Browse the repository at this point in the history
* feat(configuration): make max_batch_results configurable

* docs(readme): document environment variable

* test(integrations): updated for new default max_batch_results value
  • Loading branch information
kiran94 committed Jan 20, 2024
1 parent a4e74f9 commit 3f14716
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ fss -i AWS_SECRET_MAN | jq .
| [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) | `AWS_SECRET_MAN` |

The *Command Line Argument* above is passed as the `-i` flag. `AWS_SSM` is the default.

## Environment Variables

| Environment Variables | Description | Default |
| --------------------- | ---------- | -------- |
| `FSS_MAX_BATCH_RESULTS` | The maximum number of results to request from the underlying secret service per batch. Note that this value might be rejected by the underlying secret service. For example `boto3` validates this value to be <= 50 for AWS SSM | `50` |
12 changes: 8 additions & 4 deletions fuzzy_secret_stdout/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import argparse
import logging
Expand All @@ -14,17 +15,19 @@
logger = logging.getLogger(__name__)



def main():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--integration', choices=Integration.list_options(), default=Integration.AWS_SSM, type=Integration)
parser.add_argument("-i", "--integration", choices=Integration.list_options(), default=Integration.AWS_SSM, type=Integration)
parser.add_argument("-b", '--max-batch-size', type=int, default=os.environ.get("FSS_MAX_BATCH_RESULTS", 50), dest='max_batch_results')

args = parser.parse_args(sys.argv[1:])

search = FzfPrompt()
integration_client = create_integration(args.integration)

with Live(Spinner('dots', text=Text('Loading')), transient=True):
result: list[SecretStoreItem] = integration_client.fetch_all()
with Live(Spinner("dots", text=Text("Loading")), transient=True):
result: list[SecretStoreItem] = integration_client.fetch_all(max_batch_results=args.max_batch_results)

keys: list[str] = [x.key for x in result]

Expand All @@ -39,5 +42,6 @@ def main():
for current_result in result:
sys.stdout.write(current_result.value)

if __name__ == '__main__': # pragma: nocover

if __name__ == "__main__": # pragma: nocover
main()
2 changes: 1 addition & 1 deletion fuzzy_secret_stdout/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class SecretIntegration(ABC):

@abstractmethod
def fetch_all(self, max_batch_results: Optional[int] = 3) -> list[SecretStoreItem]: # pragma: nocover
def fetch_all(self, max_batch_results: Optional[int] = 50) -> list[SecretStoreItem]: # pragma: nocover
pass

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion fuzzy_secret_stdout/integrations/aws_secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AWSSecretManager(SecretIntegration):
def __init__(self, boto_client) -> None:
self._boto_client = boto_client

def fetch_all(self, max_batch_results: Optional[int] = 3) -> list[SecretStoreItem]:
def fetch_all(self, max_batch_results: Optional[int] = 50) -> list[SecretStoreItem]:

def inner(boto_client, **kwargs):
return boto_client.list_secrets(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion fuzzy_secret_stdout/integrations/aws_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AWSParameterStore(SecretIntegration):
def __init__(self, boto_client) -> None:
self._boto_client = boto_client

def fetch_all(self, max_batch_results: Optional[int] = 3) -> list[SecretStoreItem]:
def fetch_all(self, max_batch_results: Optional[int] = 50) -> list[SecretStoreItem]:

def inner(boto_client, **kwargs):
return boto_client.describe_parameters(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/test_aws_secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_fetch_all_no_parameters(list_secrets_return: dict):
result = integration.fetch_all()

assert result == []
assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=3)]
assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=50)]


@pytest.mark.parametrize("max_results", [
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_fetch_all__keys_no_pagination():
integration = AWSSecretManager(mock_secret_man)
result = integration.fetch_all()

assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=3)]
assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=50)]
assert result == [
SecretStoreItem(key='param1'),
SecretStoreItem(key='param2'),
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_fetch_all_keys_pagination():
SecretStoreItem(key='param4')
]

assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=3), call(NextToken='token1', MaxResults=3), call(NextToken='token2', MaxResults=3)]
assert mock_secret_man.list_secrets.call_args_list == [call(MaxResults=50), call(NextToken='token1', MaxResults=50), call(NextToken='token2', MaxResults=50)]

def test_fetch_secrets():
input = ['param1']
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/test_aws_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_fetch_all_no_parameters(describe_parameters_return: dict):
result = integration.fetch_all()

assert result == []
assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=3)]
assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=50)]


@pytest.mark.parametrize("max_results", [
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_fetch_all_ssm_keys_no_pagination():
integration = AWSParameterStore(mock_ssm)
result = integration.fetch_all()

assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=3)]
assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=50)]
assert result == [
SecretStoreItem(key='param1'),
SecretStoreItem(key='param2'),
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_fetch_all_ssm_keys_pagination():
SecretStoreItem(key='param4')
]

assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=3), call(NextToken='token1', MaxResults=3), call(NextToken='token2', MaxResults=3)]
assert mock_ssm.describe_parameters.call_args_list == [call(MaxResults=50), call(NextToken='token1', MaxResults=50), call(NextToken='token2', MaxResults=50)]


def test_fetch_secrets():
Expand Down

0 comments on commit 3f14716

Please sign in to comment.