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

Generate openapi.json response structures for approle requests #18055

Closed
wants to merge 12 commits into from

Conversation

averche
Copy link
Contributor

@averche averche commented Nov 18, 2022

This PR adds logic to generate openapi.json response structures and implements the response structures for applrole path_role requests.

Example

For GET "/auth/approle/role/{role_name}/bind-secret-id" path, it will update the response as follows:

        "responses": {
          "200": {
            "description": "OK",
++            "content": {
++              "application/json": {
++                "schema": {
++                  "$ref": "#/components/schemas/ApproleRoleBindSecretIdResponse"
++                }
++             }
            }
          }
        }

And will add the actual response structure:

++      "ApproleRoleBindSecretIdResponse": {
++        "type": "object",
++        "properties": {
++          "bind_secret_id": {
++            "type": "boolean",
++            "description": "Impose secret_id to be presented when logging in using this role. Defaults to 'true'."
++          }
++        }
++      },

@averche averche changed the title WIP: response structures in openapi.json Generate openapi.json response structures for approle requests Nov 28, 2022
@averche averche marked this pull request as ready for review November 28, 2022 15:26
sdk/framework/openapi.go Show resolved Hide resolved
builtin/credential/approle/path_role.go Show resolved Hide resolved
builtin/credential/approle/path_role.go Show resolved Hide resolved
Copy link
Contributor

@dhuckins dhuckins left a comment

Choose a reason for hiding this comment

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

took a closer look at path_role.go after meeting yesterday, far as I can tell all the functions matched up
(would really recommend moving the approle stuff into its own PR)

this looks like its not all the paths for the approle plugin

Paths: framework.PathAppend(
rolePaths(b),
[]*framework.Path{
pathLogin(b),
pathTidySecretID(b),
},
),

its more than enough code changes 😅 but can you change the PR title? right now it reads as if its the entire plugin and not only the "role" paths

Comment on lines +111 to +115
responseOK := map[int][]framework.Response{
http.StatusOK: {{
Description: "OK",
}},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to call it a "standard", but is this a frequent response for the api? maybe we can even export a var from framework

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically a Null response (with no fields). I think it's a good idea to move it out, agreed!

@@ -210,15 +210,42 @@ can only be set during role creation and once set, it can't be reset later.`,
Type: framework.TypeBool,
Description: "If true, the secret identifiers generated using this role will be cluster local. This can only be set during role creation and once set, it can't be reset later",
},
"period": {
Copy link
Contributor

Choose a reason for hiding this comment

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

so "period" is a field, was it removed? (git diff is weird)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be referencing an older commit. It's a deprecated response field but I added it back for backwards compatibility.

builtin/credential/approle/path_role.go Show resolved Hide resolved
@averche averche marked this pull request as draft November 30, 2022 17:57
@averche
Copy link
Contributor Author

averche commented Nov 30, 2022

@dhuckins Agreed, I will split this into two PR's and change the title accordingly. Thanks for the reviews!

@averche averche closed this Nov 30, 2022
averche added a commit that referenced this pull request Dec 5, 2022
This PR modifies the path schema of `approle/path_role.go`, switching the old `Callbacks` to the equivalent `Operations` objects with a list of response fields for the 200 responses. This will allow us to generate a response structures in openapi.json. This PR is split out from #18055 along with #18192.

### Example

For `GET "/auth/approle/role/{role_name}/bind-secret-id"` path, it will update the response as follows:

```diff
        "responses": {
          "200": {
            "description": "OK",
++            "content": {
++              "application/json": {
++                "schema": {
++                  "$ref": "#/components/schemas/ApproleRoleBindSecretIdResponse"
++                }
++             }
            }
          }
        }
```

And will add the actual response structure:

```diff
++      "ApproleRoleBindSecretIdResponse": {
++        "type": "object",
++        "properties": {
++          "bind_secret_id": {
++            "type": "boolean",
++            "description": "Impose secret_id to be presented when logging in using this role. Defaults to 'true'."
++          }
++        }
++      },
```
AnPucel pushed a commit that referenced this pull request Jan 14, 2023
This PR modifies the path schema of `approle/path_role.go`, switching the old `Callbacks` to the equivalent `Operations` objects with a list of response fields for the 200 responses. This will allow us to generate a response structures in openapi.json. This PR is split out from #18055 along with #18192.

### Example

For `GET "/auth/approle/role/{role_name}/bind-secret-id"` path, it will update the response as follows:

```diff
        "responses": {
          "200": {
            "description": "OK",
++            "content": {
++              "application/json": {
++                "schema": {
++                  "$ref": "#/components/schemas/ApproleRoleBindSecretIdResponse"
++                }
++             }
            }
          }
        }
```

And will add the actual response structure:

```diff
++      "ApproleRoleBindSecretIdResponse": {
++        "type": "object",
++        "properties": {
++          "bind_secret_id": {
++            "type": "boolean",
++            "description": "Impose secret_id to be presented when logging in using this role. Defaults to 'true'."
++          }
++        }
++      },
```
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