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

Switch 'osc.conf.config' from dict to Options class with type checking #1387

Merged
merged 4 commits into from
Sep 11, 2023

Conversation

dmach
Copy link
Contributor

@dmach dmach commented Aug 22, 2023

Fixes: #1371
Fixes: #1073
Obsoletes: #1377

@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Patch coverage: 72.65% and project coverage change: +1.03% 🎉

Comparison is base (e8fc97b) 29.31% compared to head (c5e4f04) 30.35%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1387      +/-   ##
==========================================
+ Coverage   29.31%   30.35%   +1.03%     
==========================================
  Files          47       49       +2     
  Lines       17291    17685     +394     
==========================================
+ Hits         5069     5368     +299     
- Misses      12222    12317      +95     
Files Changed Coverage Δ
osc/connection.py 53.26% <0.00%> (-0.27%) ⬇️
osc/credentials.py 43.57% <0.00%> (+1.36%) ⬆️
osc/commandline.py 19.08% <8.33%> (+0.02%) ⬆️
osc/conf.py 52.59% <66.24%> (+3.63%) ⬆️
osc/util/models.py 91.30% <91.30%> (ø)
osc/util/xdg.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

osc/conf.py Fixed Show fixed Hide fixed
osc/conf.py Fixed Show resolved Hide resolved
osc/conf.py Show resolved Hide resolved
osc/conf.py Outdated Show resolved Hide resolved
osc/conf.py Outdated Show resolved Hide resolved
osc/conf.py Outdated Show resolved Hide resolved
osc/conf.py Outdated Show resolved Hide resolved
osc/util/models.py Outdated Show resolved Hide resolved
@dmach dmach force-pushed the config-type-checking branch 3 times, most recently from d85bd88 to aad6a96 Compare August 24, 2023 08:09
@dmach dmach force-pushed the config-type-checking branch from aad6a96 to e824c8c Compare August 30, 2023 12:00
osc/conf.py Fixed Show fixed Hide fixed
@dmach dmach force-pushed the config-type-checking branch 2 times, most recently from c82d18c to b77a01c Compare September 5, 2023 08:53
osc/conf.py Dismissed Show dismissed Hide dismissed


def apply_option_types(config, conffile=""):
class Password(collections.UserString):

Check warning

Code scanning / CodeQL

`__eq__` not overridden when adding attributes Warning

The class 'Password' does not override
'__eq__'
, but adds the new attribute
_data
.
@dmach dmach force-pushed the config-type-checking branch 3 times, most recently from 079140f to 1046567 Compare September 11, 2023 08:38
Comment on lines 261 to 263

if options.cafile or options.capath:
ssl_context.load_verify_locations(cafile=options.cafile, capath=options.capath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried this with capath=False, which results in

...
  File "/usr/lib/python3.11/site-packages/osc/connection.py", line 268, in http_request
    ssl_context.load_verify_locations(cafile=options["cacert"], capath=False)
TypeError: capath should be a valid filesystem path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and with capath="", I get SSL Error: [X509: INVALID_DIRECTORY] invalid directory (_ssl.c:4154)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind that. With capath=None (which you default to) it works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK False is an invalid value. It should either hold a path or be None.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I hadn't seen how you read the config (and your default values) due to "large diff hidden".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I hadn't seen how you read the config (and your default values) due to "large diff hidden".

I've rendered docs for this pull request, that might be helpful too:
https://opensuse-commander.readthedocs.io/en/readthedocs-test/api/osc.conf.html
https://opensuse-commander.readthedocs.io/en/readthedocs-test/oscrc.html

@dmach dmach force-pushed the config-type-checking branch from abaa7ae to c5e4f04 Compare September 11, 2023 19:16
@dmach dmach merged commit a5f56b1 into openSUSE:master Sep 11, 2023
30 of 32 checks passed
@birkenfeld
Copy link

One question about this change... so far, I've been using oscrc to store config for my own OSC plugin. Is this still supported, and if yes, what is the way to do it? My current way seems too hacky to be proper:

class MyOptions(osc.conf.Options):
    new_field: str = Field(...)
osc.conf.Options = MyOptions

@dmach
Copy link
Contributor Author

dmach commented Oct 10, 2023

It looks like it worked, but to be honest, I don't know if it was ever supported.
In my opinion plugins should not use oscrc to store their data.
But if there's a regression and there's a reasonable (non-hackish) way of fixing it, I'll do it.

If I broke something or if you need a good support for plugin configs,
could you open a new issue so we don't discuss it in a closed pull request?

@birkenfeld
Copy link

Sure, thanks for the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

usage without a config file The get_password methods of password managers return values of different types
4 participants