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

OpenAPI CRUD views #6702

Merged
merged 38 commits into from
Jun 21, 2019
Merged

OpenAPI CRUD views #6702

merged 38 commits into from
Jun 21, 2019

Conversation

madalynrose
Copy link
Contributor

@madalynrose madalynrose commented May 8, 2019

This adds functionality to our path help service to grab relevant paths from OpenAPI to be displayed as tabs for auth methods.

Copy link
Contributor

@meirish meirish left a comment

Choose a reason for hiding this comment

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

This is looking good! I haven't pulled it down yet to try it out, but wanted to get these published - I know you're still planning on a cleanup pass - I think some of the comments I left might help with that.

Re: documentation - I think the comments are good, but could we also include a high level "this is how you use this" maybe at the top of the service?

What do you think about dropping in some https://api.emberjs.com/ember/3.10/functions/@ember%2Fdebug/debug calls in the service function s "Generating ____ model/adapter from ____ Open API endpoint" or something like that? Just thinking it'd be nice to have along with the route transition logs that we do as a check to make sure things are running properly.

ui/app/router.js Show resolved Hide resolved
this._super(...arguments);
const { item_type: itemType } = this.paramsFor(this.routeName);
const { path } = this.paramsFor('vault.cluster.access.method');
const { apiPath } = this.modelFor('vault.cluster.access.method');
Copy link
Contributor

Choose a reason for hiding this comment

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

We could wrap these into a helper method to use in both places.

ui/app/services/path-help.js Outdated Show resolved Hide resolved
//we always want to keep list endpoints for menus
//but only use scoped post/delete endpoints
if (itemType) {
paths = paths.filter(path => path.includes(itemType));
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we come across a backend that had sibling paths instead of nested ones? Will we just handle that when we come across it?

}
})
.filter(path => path != undefined);

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could do all of this in one pass with a reduce, but that's more of a cleanup thing than a must have.

{{form-field data-test-field attr=attr model=model onChange=onChange}}
{{#unless (and (not-eq mode "create") (eq attr.name "name"))}}
{{form-field data-test-field attr=attr model=model onChange=onChange
}}
Copy link
Contributor

@meirish meirish May 13, 2019

Choose a reason for hiding this comment

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

Did this just insert a line break?

ui/app/templates/components/section-tabs.hbs Outdated Show resolved Hide resolved
</ToolbarLink>
</ToolbarActions>
</Toolbar>
{{#if model.meta.total}}
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 a ListView and ListItem component that might be helpful here (not sure - it's been a while since I looked at them).

ui/app/router.js Outdated Show resolved Hide resolved
@meirish
Copy link
Contributor

meirish commented May 17, 2019

One other thing I didn't fully track down - if you go directly to the the method via the URL since there's no way to navigate there yet (we should probably link up ldap in the auth method list) - then you end up on the configuration page - can we change that so that we go to the first tab instead?

@meirish
Copy link
Contributor

meirish commented Jun 20, 2019

I don't think we want the delete button in the toolbar and at the bottom of the form - I think just in the toolbar - but @joshuaogle would know for sure!
Screen Shot 2019-06-20 at 3 21 45 PM

@meirish
Copy link
Contributor

meirish commented Jun 20, 2019

Functionally this looks great - there's a couple of things I'd like to see changed (and I can help track them down too) -

  1. we should link the ldap auth list to the new routes
  2. navigating there should take you to the groups tab since it's the first tab (that's what I was referring to in OpenAPI CRUD views #6702 (comment))

Going to look through the code now.

model: null,
tabType: 'authSettings',
});

SectionTabs.reopenClass({
positionalParams: ['model', 'tabType'],
positionalParams: ['model', 'tabType', 'paths'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note here that positionParams are going away in Glimmer components, so we'll eventually want to move away from this.

helpText:
'Use the Active Directory tokenGroups constructed attribute to find the group memberships. This returns all security groups for the user, including nested groups. In an Active Directory environment with a large number of groups this method offers increased performance. Selecting this will cause Group DN, Attribute, and Filter to be ignored.',
}),

Copy link
Contributor

Choose a reason for hiding this comment

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

uau 👏

model(params) {
// eslint-disable-line rule
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be removed.

@@ -12,7 +15,10 @@ export default Route.extend({
set(error, 'httpStatus', 404);
throw error;
}
return model;
return this.pathHelp.getPaths(model.apiPath, path).then(paths => {
model.set('paths', paths);
Copy link
Contributor

Choose a reason for hiding this comment

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

(for later) we should document what attributes OpenAPI models have on them - paths, newFields, etc.

controller.set('method', path);
const { apiPath } = this.modelFor('vault.cluster.access.method');
this.pathHelp.getPaths(apiPath, path, itemType).then(paths => {
controller.set('paths', Array.from(paths.list, pathInfo => pathInfo.path));
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the type of paths.list here?

@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be here?

@@ -63,8 +62,7 @@ export default Route.extend(UnloadModelRoute, {
if (['secret', 'secret-v2'].includes(modelType)) {
return resolve();
}
let owner = getOwner(this);
return this.pathHelp.getNewModel(modelType, owner, backend);
return this.pathHelp.getNewModel(modelType, backend);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah cool - I'll have to update these in the KMIP PR after this is merged too

//Makes a call to grab the OpenAPI document.
//Returns relevant information from OpenAPI
//as determined by the expandOpenApiProps util
getProps(helpUrl, backend) {
debug(`Fetching schema properties for ${backend} from ${helpUrl}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@@ -24,37 +30,252 @@ export default Service.extend({
});
},

getNewModel(modelType, backend, apiPath, itemType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is itemType here? I think a comment with example usage of the method would help too

Copy link
Contributor

@andaley andaley Jul 21, 2020

Choose a reason for hiding this comment

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

itemType is the type of nested item, i.e. a LDAP group or userpass user. here's an example of where the itemType is set in the go code: https://github.com/hashicorp/vault/pull/7513/files#diff-cb2f72de1a3a7afc5227ef80f58f99f9R24

(also lol hi delayed answer here 🙈 -- just marking up this PR with notes for the rest of the team)

@@ -225,4 +179,4 @@
value=(if (get model valuePath) (stringify (get model valuePath)) emptyData)
valueUpdated=(action "codemirrorUpdated" attr.name false)
}}
{{/if}}
{{/if}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any changes in this file other than whitespace? I think the formatting before was easier to read fwiw - if it's just whitespace changes, could we back these out?

{{/link-to}}
{{/if}}
</div>
<div class="control">
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the div and contents we'd remove if we don't need the Delete button on the bottom.

</button>
</div>
</button>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the old one was broken with some indentation, but I think the whitespace was better before even with the bad indentation.

</p.top>
<p.levelLeft>
<h1 class="title is-3">
{{capitalize method}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add an Icon above this? - should this be method or the path for the auth method?

Copy link
Contributor

Choose a reason for hiding this comment

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

So I think this should be id of the method

@meirish meirish added this to the 1.2 milestone Jun 20, 2019
meirish
meirish previously approved these changes Jun 21, 2019
Copy link
Contributor

@meirish meirish left a comment

Choose a reason for hiding this comment

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

I think we should merge this and iterate on it after merge, but this should be good for the beta 🙌

export default AuthConfig.extend({
useOpenAPI: true,
binddn: attr('string', {
Copy link
Contributor

Choose a reason for hiding this comment

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

notice here that when we set useOpenAPI to true, we can get rid of the duplicate attrs. OpenAPI gives us the attrs and sets them on the model here: https://github.com/hashicorp/vault/pull/6702/files#diff-cd3b672bded0741ca8ec360a4deb124fR37

let methodModel = this.modelFor('vault.cluster.access.method');
let { apiPath, type } = methodModel;
let modelType = `generated-${singularize(itemType)}-${type}`;
return this.pathHelp.getNewModel(modelType, method, apiPath, itemType);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an example of how we call OpenAPI and generate a model on the auth method items pages.

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.

4 participants