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

WIP: Add databricks permissions command #314

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

areese
Copy link
Contributor

@areese areese commented Aug 17, 2020

This is a public preview api

Copy link

@gauthamsunjay gauthamsunjay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Left some comments.

}


class PermissionsApi(object):

Choose a reason for hiding this comment

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

This class doesn't expose a way to set / update permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that's a good point I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add update, but looking at https://docs.databricks.com/dev-tools/api/latest/permissions.html#operation/update-all-notebook-permissions

I'm kinda skeptical of set_permissions. The issue I have is it's dangerous, you could wipe all permission out everywhere if you are not careful.

I'm going to leave that out of this pr, and start a thread with engineering to determine if that's something that should be exposed.

databricks_cli/permissions/api.py Outdated Show resolved Hide resolved
databricks_cli/permissions/cli.py Outdated Show resolved Hide resolved
return

click.echo(pretty_format(perms_api.add_permissions(object_type, object_id, all_permissions)))

Choose a reason for hiding this comment

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

We should add support for the following:

  1. Set / update permissions
  2. Ability to specify multiple permissions (not sure if this is possible already)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take note of that.

I also need to add some tests, and I'll cover those as part of the tests.

}
}


Choose a reason for hiding this comment

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

Can we add tests for other operations as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. :). Oversight.

I'm trying to collect all of the bits I have, and get them pushed.
Once there are tests and better coverage, we can take another look.

@areese areese changed the title Add databricks permissions command WIP: Add databricks permissions command Sep 18, 2020
@areese
Copy link
Contributor Author

areese commented Sep 18, 2020

This is still WIP, there are a number of requests from @gauthamsunjay that need to be addressed, once those are fixed, we can review again.

Allen Reese added 17 commits September 22, 2020 09:47
Move from argument to option so help can be provided.
Share the same help text across all of the databricks permissions functions
Move from --object_type to --object-id to be inline with other commands
Fix tests to validate the test output the same way clusters does
…ype hint not being the first line of the functions

Remove an unused variable from tests/permissions/test_cli.py
1. Reuse the same help string for all object types
2. Update the group help to display the object types, it could be hard coded or displayed a lot cleaner.
3. object-id is always required, even on list, need to find out why
4. Remove if not object_type checks, as object type is a required option
5. Add mostly complete tests for list-permission-types, I do not have registered-models or instance-pools data available
Fix line too long lint errors.
Fix errors looking up instance-pools in the enum
$ databricks permissions add  --object-type clusters --object-id foo
Error: Missing None.  One of ['group-name', 'user-name', 'service-name'] must be provided.

$ databricks permissions add  --object-type clusters --object-id foo
Error: Missing option '--group-name'.  One of ['group-name', 'user-name', 'service-name'] must be provided.
Cleanup ordering of commands added to the group
Remove checks that are done by click and are not required in databricks permissions add
Rename databricks_cli/permissions/api.py:Lookups to PermissionsLookup
PermissionsLookup.from_name should raise a useful error with a message instead of KeyError
Remove more error checking that is done by click.
--permission-level should be checked by click to provide a useful error
Use click.Choice to validate permission levels
Add test for databricks permissions add clusters manage
Allow PermissionsObject to init with constructor
databricks permissions ls should require path, and path should have help
Add more tests
Remove dead code that wasn't called
Update tests to cover all of the commands
Copy link
Contributor

@nfx nfx left a comment

Choose a reason for hiding this comment

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

please see comments



class PermissionTargets(Enum):
clusters = 'clusters'
Copy link
Contributor

Choose a reason for hiding this comment

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

logically this should rather be a dictionary or list of tuples, because it's mixing two different things under same enumeration.

e.g. cluster is the object type and clusters is the prefix for object it,

return ', '.join([e.value for e in PermissionLevel])


class BasicPermissions(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks over-engineered. please simplify.

technically, it all can be replaced by single simple lookup structure.

@click.command(context_settings=CONTEXT_SETTINGS,
short_help='Get permissions for an item. ' + POSSIBLE_OBJECT_TYPES)
@click.option('--object-type', required=True, help=POSSIBLE_OBJECT_TYPES)
@click.option('--object-id', required=True, help='object id to require permission about')
Copy link
Contributor

Choose a reason for hiding this comment

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

why not providing one of kind of arguments? e.g. --cluster-id, --job-id, --tokens, --passwords, --cluster-policy-id and etc? CLI is supposed to simplify usage for admins and not always be 1-1 mapping to API resources.

@click.option('--group-name', metavar='<string>', cls=OneOfOption,
one_of=GROUP_USER_SERVICE_OPTIONS)
@click.option('--user-name', metavar='<string>', cls=OneOfOption, one_of=GROUP_USER_SERVICE_OPTIONS)
@click.option('--service-name', metavar='<string>', cls=OneOfOption,
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not really a service name, but --service-principal

# limitations under the License.


class PermissionsError(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need a file for two lines of code? why it cannot be in the same file as where it's thrown from?

@@ -0,0 +1,95 @@
from typing import Optional

from databricks_cli.sdk.preview_service import PreviewService
Copy link
Contributor

Choose a reason for hiding this comment

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

there's no such a thing as preview service. please remove or rename to something like PreviewStability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's reasonable.

I'm probably going to use the newer openapi spec that is part of the rest specification and rewrite this differently.

@areese
Copy link
Contributor Author

areese commented Jan 6, 2021

FYI: This is stale, it has semi-useful code but has a lot to be addressed.
I'm going to leave it open, but I'm not sure how fast I'll come back to it.

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.

3 participants