Comments (11)
So the documentation doesn't actually specify this behavior but basically you can have the endpoint return the list of all accessible repositories in the installation by specifying an empty array for the repositories parameter. It saved a round trip to the separate endpoint.
Command with empty array
curl -s "https://api.github.com/app/installations/$APP_INSTALL_ID/access_tokens" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $APP_JWT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d '{"repositories":[],"permissions":{"contents":"read"}}'
Output
{
"token": "<token>",
"expires_at": "2024-03-17T02:30:32Z",
"permissions": {
"contents": "read",
"metadata": "read"
},
"repositories": ["<all repos in installation...>"],
"repository_selection": "all"
}
Command with null or no repositories
curl -s "https://api.github.com/app/installations/$APP_INSTALL_ID/access_tokens" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $APP_JWT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d '{"repositories":null,"permissions":{"contents":"read"}}'
# OR
curl -s "https://api.github.com/app/installations/$APP_INSTALL_ID/access_tokens" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $APP_JWT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d '{"permissions":{"contents":"read"}}'
Output
{
"token": "<token>",
"expires_at": "2024-03-17T02:30:32Z",
"permissions": {
"contents": "read",
"metadata": "read"
},
"repository_selection": "all"
}
from go-github.
Got it. If there are no objections I'll just move forward with CreateInstallationTokenListRepos as a name for the new endpoint function. If my week goes to plan hopefully I can get a PR in by Friday.
from go-github.
@gmlewis Hi thanks for following up. The examples given are correct, the -d
argument changes the request method to POST
as demonstrated in the examples on the man page.
Sorry for the confusion.
from go-github.
According to the official docs:
Optionally, you can use the repositories or repository_ids body parameters to specify individual repositories that the installation access token can access. If you don't use repositories or repository_ids to grant access to specific repositories, the installation access token will have access to all repositories that the installation was granted access to. The installation access token cannot be granted access to repositories that the installation was not granted access to. Up to 500 repositories can be listed in this manner.
so these fields are optional, hence the omitempty
, and it's not clear (to me) what the behavior is if you were to send it an empty array (as opposed to not sending the field at all, which omitempty
does).
You didn't state what you are trying to do by providing it an empty array.
Are you trying to remove access to all repositories? If so, I'm wondering if that might be a different endpoint, such as this one?
If you are trying to do something else, then I need to warn you against removing omitempty
from optional body parameters, as that has historically wreaked havoc with other uses of the endpoint, and we've had to create additional endpoints to address the other behavior.
So please clarify what you are trying to do, and if you would like to create a PR to address the issue.
Thanks.
from go-github.
Awesome... Thank you for the detailed example!
Then I'm thinking we need to have a new, separate endpoint that handles this special case... with a name that makes the distinction clear.
What do you think?
Do you want to write it, @gillisandrew ?
from go-github.
Hello. If @gillisandrew doesn't want to take this I'd like to have a crack at it. Thanks!
from go-github.
Thank you, @Matthew-Reidy ! It's yours.
from go-github.
Hey all, I will begin working on this today but I just want to make sure I understand what the problem is here before I start. Basically passing an empty array of repositories as a parameter should return a list of all repos that are a part of an installation but the client discards empty arrays?
from go-github.
Hey all, I will begin working on this today but I just want to make sure I understand what the problem is here before I start. Basically passing an empty array of repositories as a parameter should return a list of all repos that are a part of an installation but the client discards empty arrays?
Actually, I'm a bit confused now myself. The original description talks about a POST
call, but the example given is a GET
call.
@gillisandrew - can you please clarify what your ask is here, and exactly which go-github
endpoint(s) you are talking about?
from go-github.
Oh, cool! TIL. Sorry, @gillisandrew - my bad... both are the POST
case.
OK, so @Matthew-Reidy - we need a new endpoint...
The endpoint we are talking about is CreateInstallationToken
.
Now the hard part - what should the name be?
Maybe CreateInstallationTokenListRepos
? @gillisandrew - ideas?
Now the easy part is that this new method will have an internal anonymous struct almost identical to InstallationTokenOptions
with the one modification:
RepositoryIDs []int64 `json:"repository_ids"`
and this field will not be assigned a value.
@gillisandrew - have I got all this right?
from go-github.
Submitted a PR to fix this.
from go-github.
Related Issues (20)
- Update deprecated endpoints in github/action_variables.go HOT 4
- `NewTeam` missing `notification_setting` field HOT 1
- feat: Add an option to wait for primary rate limit reset and retry instead of erroring out HOT 7
- Username is required when using fine-grained vs classic PAT (personal access token) for PlainClone operation
- LIst of issue comments do not collect the comment which was added during the creation of the PR. HOT 6
- Use enums for the action field in GitHub Webhooks HOT 4
- Can't remove repository ruleset's every Bypass Actors because of serialization issue HOT 4
- Support new REST API endpoint that evaluates if private vulnerability reporting is enabled HOT 4
- Webhook MemberEvent Type is Missing Changes Object
- Bug: Issues.ListByRepo Repository field is always `nil` HOT 5
- `ListRunnersOption` change omits consideration of Enterprise Runner HOT 4
- Add support for CommitID, InReplyTo, and SubjectType to DraftReviewComment HOT 1
- Support for merge queues. HOT 3
- Bug: GetArchiveLink returns a status code 200, not 302, when link is requested with an installation token rather than personal/bearer token HOT 3
- WorkflowRun struct does not include `path` property HOT 1
- Proposal: Add GitHub App Token and Installation Token Source Functionality HOT 6
- GetEnterpriseRunner method appears to be missing HOT 1
- RepositoryPermissionLevel is missing role_name
- Space being stripped from Workflow Run, Job, and Step Names HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-github.