Skip to content

Extract security.privileges.query in a typealias #1735

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

Merged
merged 4 commits into from
Jun 3, 2022

Conversation

Anaethelion
Copy link
Contributor

No description provided.

@swallez swallez self-requested a review June 3, 2022 09:03
Copy link
Member

@swallez swallez left a comment

Choose a reason for hiding this comment

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

From the ES source code, the type for IndicesPrivilegesQuery is string | QueryContainer | RoleTemplateQueryContainer | null (not a string array).

I think we can ignore null as it has the same result as not including the query field.

The string is interpreted as QueryContainer | RoleTemplateQueryContainer in "json as text" (see also the doc). ES uses this string format internally, and will always serialize this field as a json-as-text (i.e. the string variant).

Additionally, RoleTemplateQueryContainer is not a container, it's a simple structure that has a single template: Script field (we don't need RoleTemplateQueryContainer).

And finally, we need a @codegen_name on the union type to identify the variants.

So that should be:

export class IndicesPrivileges {
  ...
  query?: IndicesPrivilegesQuery
}

/**
 * ... explain that text and JSON are accepted in requests, but that responses
 * will always contain the text version.
 * 
 * @codegen_name text, query, template
 */
export type IndicesPrivilegesQuery = string | QueryContainer | RoleTemplateQuery

export class RoleTemplateQueryContainer {
  ...
  template?: Script
}

Add comments to clarify usage and intent in requests & responses
@Anaethelion Anaethelion force-pushed the lsf/fix/security.privileges branch from 9c0b917 to 2eb2281 Compare June 3, 2022 10:52
@Anaethelion Anaethelion requested a review from swallez June 3, 2022 10:59
Copy link
Member

@swallez swallez left a comment

Choose a reason for hiding this comment

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

LGTM, with minor comments

Change codegen text to json_text for clarity
@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2022

Following you can find the validation results for the APIs you have changed.

API Status Request Response
security.activate_user_profile Missing test Missing test
security.authenticate 🟢 15/15 15/15
security.change_password 🟢 6/6 6/6
security.clear_api_key_cache 🟢 9/9 9/9
security.clear_cached_privileges 🟢 3/3 3/3
security.clear_cached_realms 🟢 1/1 1/1
security.clear_cached_roles 🟢 2/2 2/2
security.clear_cached_service_tokens 🟢 4/4 4/4
security.create_api_key 🔴 18/25 16/16
security.create_service_token 🟢 2/2 2/2
security.delete_privileges 🟢 6/6 6/6
security.delete_role_mapping 🟢 9/9 9/9
security.delete_role 🟢 8/8 8/8
security.delete_service_token Missing test Missing test
security.delete_user 🟢 9/9 9/9
security.disable_user_profile Missing test Missing test
security.disable_user 🟢 3/3 3/3
security.enable_user_profile Missing test Missing test
security.enable_user 🟢 4/4 4/4
security.enroll_kibana Missing test Missing test
security.enroll_node Missing test Missing test
security.get_api_key 🟢 14/14 14/14
security.get_builtin_privileges 🟢 2/2 2/2
security.get_privileges 🟢 12/12 12/12
security.get_role_mapping 🟢 18/18 18/18
security.get_role 🟢 20/20 20/20
security.get_service_accounts Missing test Missing test
security.get_service_credentials 🟢 1/1 1/1
security.get_token 🟢 21/21 20/20
security.get_user_privileges 🔴 7/7 4/7
security.get_user_profile Missing test Missing test
security.get_user 🟢 24/24 24/24
security.grant_api_key 🟢 12/12 12/12
security.has_privileges 🟢 9/9 9/9
security.invalidate_api_key 🟢 10/10 10/10
security.invalidate_token 🟢 11/11 11/11
security.oidc_authenticate 🟠 Missing type Missing type
security.oidc_logout 🟠 Missing type Missing type
security.oidc_prepare_authentication 🟠 Missing type Missing type
security.put_privileges 🟢 10/10 10/10
security.put_role_mapping 🟢 11/11 11/11
security.put_role 🟢 26/26 25/25
security.put_user 🟢 39/39 38/38
security.query_api_keys 🟢 7/7 7/7
security.saml_authenticate Missing test Missing test
security.saml_complete_logout Missing test Missing test
security.saml_invalidate Missing test Missing test
security.saml_logout Missing test Missing test
security.saml_prepare_authentication Missing test Missing test
security.saml_service_provider_metadata Missing test Missing test
security.suggest_user_profiles Missing test Missing test
security.update_user_profile_data Missing test Missing test

You can validate these APIs yourself by using the make validate target.

@Anaethelion Anaethelion merged commit 906a519 into main Jun 3, 2022
@Anaethelion Anaethelion deleted the lsf/fix/security.privileges branch June 3, 2022 12:31
@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2022

The backport to 7.17 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-7.17 7.17
# Navigate to the new working tree
cd .worktrees/backport-7.17
# Create a new branch
git switch --create backport-1735-to-7.17
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 906a519c49fe09c81f3a95552208c6dbcf7dcd0b
# Push it to GitHub
git push --set-upstream origin backport-1735-to-7.17
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-7.17

Then, create a pull request where the base branch is 7.17 and the compare/head branch is backport-1735-to-7.17.

github-actions bot pushed a commit that referenced this pull request Jun 3, 2022
* Extract security.privileges.query in a typealias

* Change union type in favor a unique string
Add comments to clarify usage and intent in requests & responses

* Add backquotes for types clarity in comments
Change codegen text to json_text for clarity

* Rename RoleTemplateQuery as this is not a container
Anaethelion added a commit that referenced this pull request Jun 3, 2022
* Extract security.privileges.query in a typealias

* Change union type in favor a unique string
Add comments to clarify usage and intent in requests & responses

* Add backquotes for types clarity in comments
Change codegen text to json_text for clarity

* Rename RoleTemplateQuery as this is not a container
Anaethelion added a commit that referenced this pull request Jun 3, 2022
* Extract security.privileges.query in a typealias

* Change union type in favor a unique string
Add comments to clarify usage and intent in requests & responses

* Add backquotes for types clarity in comments
Change codegen text to json_text for clarity

* Rename RoleTemplateQuery as this is not a container
Anaethelion added a commit that referenced this pull request Jun 3, 2022
* Extract security.privileges.query in a typealias

* Change union type in favor a unique string
Add comments to clarify usage and intent in requests & responses

* Add backquotes for types clarity in comments
Change codegen text to json_text for clarity

* Rename RoleTemplateQuery as this is not a container

Co-authored-by: Laurent Saint-Félix <[email protected]>
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.

2 participants