Skip to content

Add Organization PAT fields to InstallationPermissions struct - #3243

Merged
gmlewis merged 2 commits into
google:masterfrom
hi120ki:add-organization-pat-installation
Aug 21, 2024
Merged

Add Organization PAT fields to InstallationPermissions struct#3243
gmlewis merged 2 commits into
google:masterfrom
hi120ki:add-organization-pat-installation

Conversation

@hi120ki

Copy link
Copy Markdown
Contributor

In the article "Organization APIs for fine-grained PATs management", following new 2 permissions are added to GitHub Apps

  • organization_personal_access_tokens
  • organization_personal_access_token_requests

These permissions are used for getting and updating GitHub Organization's Fine-grained PAT's lists, requests, revokes.

APIs of Organization permissions for "Personal access tokens"
APIs of Organization permissions for "Personal access token requests"

We can test these permissions following test codes, and successfully I got installation token from GitHub.

package main
import (
"context""log""net/http""github.com/bradleyfalzon/ghinstallation/v2""github.com/google/go-github/v64/github"
)
funcmain() {
ctx:=context.Background()
tr:=http.DefaultTransportitr, err:= ghinstallation.NewAppsTransportKeyFromFile(tr, <your-app-id>, <your-private-key-path>)
iferr!=nil {
log.Fatal(err)
}
client:=github.NewClient(&http.Client{Transport: itr})
token, _, err:=client.Apps.CreateInstallationToken(
ctx,
<your-installation-id>,
&github.InstallationTokenOptions{
Permissions: &github.InstallationPermissions{
OrganizationPersonalAccessTokens: github.String("read"),
OrganizationPersonalAccessTokenRequests: github.String("read"),
},
})
iferr!=nil {
log.Fatal(err)
}
log.Println(token.GetToken())
}

In the article "[Organization APIs for fine-grained PATs management](https://github.blog/changelog/2023-03-24-organization-apis-for-fine-grained-pats-management/)", following new 2 permissions are added to GitHub Apps
- organization_personal_access_tokens
- organization_personal_access_token_requests
These permissions are used for getting and updating GitHub Organization's Fine-grained PAT's lists, requests, revokes.
[APIs of Organization permissions for "Personal access tokens"](https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps?apiVersion=2022-11-28#organization-permissions-for-personal-access-tokens)
[APIs of Organization permissions for "Personal access token requests"](https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps?apiVersion=2022-11-28#organization-permissions-for-personal-access-token-requests)
We can test these permissions following test codes, and successfully I got installation token from GitHub.
```go
package main
import (
"context"
"log"
"net/http"
"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v64/github"
)
func main() {
ctx := context.Background()
tr := http.DefaultTransport
itr, err := ghinstallation.NewAppsTransportKeyFromFile(tr, <your-app-id>, <your-private-key-path>)
if err != nil {
log.Fatal(err)
}
client := github.NewClient(&http.Client{Transport: itr})
token, _, err := client.Apps.CreateInstallationToken(
ctx,
<your-installation-id>,
&github.InstallationTokenOptions{
Permissions: &github.InstallationPermissions{
OrganizationPersonalAccessTokens: github.String("read"),
OrganizationPersonalAccessTokenRequests: github.String("read"),
},
})
if err != nil {
log.Fatal(err)
}
log.Println(token.GetToken())
}
```
Signed-off-by: Hi120ki <12624257+hi120ki@users.noreply.github.com>
@google-cla

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gmlewis

Copy link
Copy Markdown
Collaborator

Thank you, @hi120ki !
Please run step 4 in our CONTRIBUTING.md guide to update our generated files.

@codecov

codecovBot commented Aug 21, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.95%. Comparing base (2b8c7fa) to head (255b0c1).
Report is 100 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #3243 +/- ##
==========================================
- Coverage 97.72% 92.95% -4.78% 
==========================================
Files 153 171 +18 Lines 13390 11646 -1744 ==========================================
- Hits 13085 10825 -2260 - Misses 215 727 +512 - Partials 90 94 +4 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…, and passed the test and lint
I checked following commands are passed.
```
$ script/fmt.sh
$ script/test.sh
$ script/lint.sh
```
Signed-off-by: Hi120ki <12624257+hi120ki@users.noreply.github.com>
@gmlewisgmlewis changed the title Add : Organization PAT installationAdd Organization PAT fields to InstallationPermissions structAug 21, 2024

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @hi120ki !
LGTM.
Merging.

@gmlewis
gmlewis merged commit 90bf432 into google:masterAug 21, 2024
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
Sign up for freeto 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.

2 participants

@hi120ki@gmlewis