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

gitfs w/pygit2 - corner case, traceback with short hexidecimal environment names #34213

Closed
terminalmage opened this issue Jun 22, 2016 · 2 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt File Servers fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 ZD The issue is related to a Zendesk customer support ticket. ZRELEASED - 2015.8.11 ZRELEASED - 2016.3.2
Milestone

Comments

@terminalmage
Copy link
Contributor

terminalmage commented Jun 22, 2016

Description of Issue/Question

Setup

Configure two gitfs remotes. One of them must have a branch with a 3-character-or-less hexidecimal name (e.g. abc), while the other must not.

Steps to Reproduce Issue

Try to list files in the short-named hexidecimal environment mentioned above.

salt-run fileserver.file_list saltenv=abc

This results in a traceback due to some code in gitfs which allows one to use a commit SHA as a gitfs environment:

Traceback (most recent call last):
...
<snip>
...
  File "/usr/lib/python2.7/site-packages/salt/utils/gitfs.py", line 1388, in get_tree 
    commit = self.repo.revparse_single(tgt_ref)
ValueError: abc: Ambiguous lookup - OID prefix is too short

What's happening here is that abc happens to be A) hexidecimal, causing the rev-parse code in libgit2 to treat it as a commit SHA, and B) shorter than the minimum SHA length (defined as 4 by libgit2, as seen here), leading to an error being raised by pygit2. The ValueError simply needs to be caught in the try/except block surrounding the call to self.repo.revparse_single().

Versions Report

Affects 2015.8.0 and newer.

@terminalmage terminalmage added Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt P3 Priority 3 File Servers TEAM Core labels Jun 22, 2016
@terminalmage terminalmage added this to the C 8 milestone Jun 22, 2016
@terminalmage terminalmage self-assigned this Jun 22, 2016
@terminalmage
Copy link
Contributor Author

ZD-820

@terminalmage terminalmage added the ZD The issue is related to a Zendesk customer support ticket. label Jun 22, 2016
terminalmage added a commit to terminalmage/salt that referenced this issue Jun 22, 2016
Hex SHAs which are less than 4 characters will raise a ValueError, this
commit catches these exceptions.

See saltstack#34213 for more information.
@terminalmage
Copy link
Contributor Author

Fixed in #34218.

@terminalmage terminalmage added the fixed-pls-verify fix is linked, bug author to confirm fix label Jun 22, 2016
rallytime pushed a commit that referenced this issue Jun 22, 2016
* Add salt.utils.is_hex()

* dulwich: use salt.utils.is_hex() to confirm ref is hexidecimal

* Restore ability for SHA1 saltenvs to be used in gitfs

This uses salt.utils.is_hex() to check if the desired environment is
hex, and allowing it to be used for gitfs operations when it is.

* pygit2: Catch ValueError when trying to resolve SHA1

Hex SHAs which are less than 4 characters will raise a ValueError, this
commit catches these exceptions.

See #34213 for more information.
garethgreenaway pushed a commit to salt-extensions/saltext-namecheap that referenced this issue Oct 31, 2023
* Add salt.utils.is_hex()

* dulwich: use salt.utils.is_hex() to confirm ref is hexidecimal

* Restore ability for SHA1 saltenvs to be used in gitfs

This uses salt.utils.is_hex() to check if the desired environment is
hex, and allowing it to be used for gitfs operations when it is.

* pygit2: Catch ValueError when trying to resolve SHA1

Hex SHAs which are less than 4 characters will raise a ValueError, this
commit catches these exceptions.

See saltstack/salt#34213 for more information.
snelzing pushed a commit to salt-extensions/saltext-mattermost that referenced this issue Dec 17, 2023
* Add salt.utils.is_hex()

* dulwich: use salt.utils.is_hex() to confirm ref is hexidecimal

* Restore ability for SHA1 saltenvs to be used in gitfs

This uses salt.utils.is_hex() to check if the desired environment is
hex, and allowing it to be used for gitfs operations when it is.

* pygit2: Catch ValueError when trying to resolve SHA1

Hex SHAs which are less than 4 characters will raise a ValueError, this
commit catches these exceptions.

See saltstack/salt#34213 for more information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt File Servers fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 ZD The issue is related to a Zendesk customer support ticket. ZRELEASED - 2015.8.11 ZRELEASED - 2016.3.2
Projects
None yet
Development

No branches or pull requests

2 participants