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

key_id is required for Creating or updating a repo secret #403

Closed
AjkayAlan opened this issue Jun 23, 2021 · 2 comments
Closed

key_id is required for Creating or updating a repo secret #403

AjkayAlan opened this issue Jun 23, 2021 · 2 comments
Labels
Type: Bug Something isn't working as documented
Projects

Comments

@AjkayAlan
Copy link

When creating or updating a repo secret (https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret), https://octokit.github.io/rest.js/v18#actions-create-or-update-repo-secret shows optional. However, if you make an API request without providing key_id, you will get a 422 invalid request:

{
    "errorType": "HttpError",
    "errorMessage": "Invalid request.\n\n\"key_id\" wasn't supplied.",
    "code": 422,
    "name": "HttpError",
    "status": 422,
    "response": {
        "url": "https://api.github.com/repos/myorg/myrepo/actions/secrets/mysecret",
        "status": 422,
        "data": {
            "message": "Invalid request.\n\n\"key_id\" wasn't supplied.",
            "documentation_url": "https://docs.github.com/rest/reference/actions#create-or-update-a-repository-secret"
        }
    },
    "request": {
        "method": "PUT",
        "url": "https://api.github.com/repos/myorg/myrepo/actions/secrets/mysecret",
        "headers": {
            "accept": "application/vnd.github.v3+json",
            "user-agent": "octokit-request.js/5.6.0 Node.js/14.17.0 (linux; x64)",
            "authorization": "token [REDACTED]",
            "content-type": "application/json; charset=utf-8"
        },
        "body": "{\"encrypted_value\":\"TheEncryptedValueHere"}",
        "request": {}
    },
    "stack": [
        "HttpError: Invalid request.",
        "",
        "\"key_id\" wasn't supplied.",
        "    at /var/task/index.js:3:35066",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)",
        "    at async XI (/var/task/index.js:5:53816)",
        "    at async DA.addSecretToRepo (/var/task/index.js:100:105846)",
        "    at async Promise.all (index 0)",
        "    at async DA.setSecretsOnRepo (/var/task/index.js:100:105423)",
        "    at async bL (/var/task/index.js:100:106485)",
        "    at async QOe (/var/task/index.js:101:1623)",
        "    at async Runtime.GOe [as handler] (/var/task/index.js:101:1073)"
    ]
}

So, the following does not work:

    const response = await this.makeRequest('PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}', {
      owner: "myorg",
      repo: "myrepo",
      secret_name: "mysecret",
      encrypted_value: "myencryptedvalue",
    });

However, this does work:

    const keyResponse = await this.makeRequest('GET /repos/{owner}/{repo}/actions/secrets/public-key', {
      owner: "myorg",
      repo: "myrepo",
    });

    const response = await this.makeRequest('PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}', {
      owner: "myorg",
      repo: "myrepo",
      secret_name: "mysecret",
      encrypted_value: "myencryptedvalue",
      key_id: keyResponse.data.key_id,
    });

Can the docs be updated to reflect this?

@ghost ghost added this to Inbox in JS Jun 23, 2021
@wolfy1339
Copy link
Member

We can't do anything at the octokit level. We take the OpenAPI spec from GitHub and automatically generate all the endpoints with the required parameters, and output all of that into docs.

The problem lies upstream here: https://github.com/github/rest-api-description/

@AjkayAlan
Copy link
Author

I went ahead and created github/rest-api-description#419. I'll continue the conversation there.

JS automation moved this from Bugs to Done Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
No open projects
JS
  
Done
Development

No branches or pull requests

2 participants