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

Auth tidy #613

Merged
merged 8 commits into from
Jul 10, 2024
Merged

Auth tidy #613

merged 8 commits into from
Jul 10, 2024

Conversation

oliver-sanders
Copy link
Member

@oliver-sanders oliver-sanders commented Jul 4, 2024

(low priority)

Looking into the feasibility of making a change to the auth code.

Before changing anything around, I wanted to get the coverage up.

Overview:

  • Blacken code.
  • Simplify code.
  • Fill some test holes.

Full details in the individual commit messages (easier to review changes one by one).

As always with auth code changes (even ones like this which shouldn't change any functionality), please extensively test this (note you can use exvcylc17 for this)!

Plz squash merge.

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included (or explain why tests are not needed).
  • CHANGES.md entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

* Blacken code.
* Put permissions in order.
* Add comments.
* Use Google-style docstrings.
* This was doing what @Property does by itself.
* Because attrs were being accessed via the class rather than the
  instance, it wasn't offering any safety.
* Switched to @Property and accessing it via the instance.
* Rationalise the configuration object type earlier.
* This avoids managing multiple data types throughout the code.
* Replace the `owner_user_info` dictionary (which contained two keys,
  one of which was duplicated) into variables.
* This removes unnecessary dictionary lookups, the potential for key
  errors and makes typing easier.
* Also add tests covering the snake/camel case calling of
  the is_permitted interface.
@wxtim wxtim merged commit f42ebfa into cylc:master Jul 10, 2024
3 of 4 checks passed
@oliver-sanders oliver-sanders deleted the auth-tidy branch July 11, 2024 08:01
Comment on lines -551 to +552
self.config.CylcUIServer.user_authorization,
self.config.CylcUIServer.site_authorization,
self.log
self.config.CylcUIServer.user_authorization.to_dict(),
self.config.CylcUIServer.site_authorization.to_dict(),
Copy link
Member

@MetRonnie MetRonnie Jul 12, 2024

Choose a reason for hiding this comment

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

I have just pulled and now getting an error when accessing cylc hub

[W 2024-07-12 14:51:13.403 CylcHubApp manager:363] cylc.uiserver | extension failed loading with message: AttributeError("'dict' object has no attribute 'to_dict'")
    Traceback (most recent call last):
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 359, in load_extension
        extension.load_all_points(self.serverapp)
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 231, in load_all_points
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 231, in <listcomp>
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 222, in load_point
        return point.load(serverapp)
               ^^^^^^^^^^^^^^^^^^^^^
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 150, in load
        return loader(serverapp)
               ^^^^^^^^^^^^^^^^^
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/application.py", line 474, in _load_jupyter_server_extension
        extension.initialize()
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/application.py", line 436, in initialize
        self._prepare_handlers()
      File "~/.conda/envs/cylc8/lib/python3.11/site-packages/jupyter_server/extension/application.py", line 326, in _prepare_handlers
        self.initialize_handlers()
      File "~/github/cylc-uiserver/cylc/uiserver/app.py", line 464, in initialize_handlers
        self.authobj = self.set_auth()
                       ^^^^^^^^^^^^^^^
      File "~/github/cylc-uiserver/cylc/uiserver/app.py", line 552, in set_auth
        self.config.CylcUIServer.site_authorization.to_dict(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'dict' object has no attribute 'to_dict'

In our site config, c.CylcUIServer.site_authorization is a dict

Copy link
Member Author

@oliver-sanders oliver-sanders Jul 12, 2024

Choose a reason for hiding this comment

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

I couldn't see a case where this would be a dict, no I know.

I have no idea why using the hub would cause the configuration object to differ, but an easy fix.

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

Successfully merging this pull request may close these issues.

4 participants