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

Fix certificates globbing from relative paths for keychain add-certificates #374

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Nov 13, 2023

It is possible to specify custom certificate paths or path patterns for action keychain add-certificates via CLI option --certificate. As this option accepts either path literals, or a glob patterns to match certificates, then relative reference . to current directory should also be an acceptable input. This however results in an error when globbing matches:

>>> list(Path().glob('.'))
Traceback (most recent call last):
  File "/Users/priit/development/nevercode/cli-tools/.venv/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-23-b1f87bcdf599>", line 1, in <cell line: 0>
    list(Path().glob('.'))
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 1094, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour, case_sensitive)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 83, in _make_selector
    pat = pattern_parts[0]
          ~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

To overcome that limitation, just resolve the relative path pattern before attempting glob search. Then the path becomes absolute which can be safely globbed.

Updated actions:

  • keychain add-certificates

@priitlatt priitlatt added the bug Something isn't working label Nov 13, 2023
@priitlatt
Copy link
Contributor Author

Some QA notes:

  1. Adding certs from ., .., etc fails since those are directories.
  2. Default case without specifying custom certificate paths/patterns still works as expected.
  3. Specifying custom relative path works as expected.
  4. Specifying custom relative path pattern works as expected.
  5. Specifying custom absolute path works as expected.
Screenshot

Screenshot 2023-11-13 at 12 52 53

@priitlatt priitlatt marked this pull request as ready for review November 13, 2023 10:54
@priitlatt priitlatt merged commit b68d8cb into master Nov 13, 2023
7 checks passed
@priitlatt priitlatt deleted the bugfix/keychain-add-certificates-globbing branch November 13, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants