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

Add Organization PAT fields to InstallationPermissions struct #3243

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

hi120ki
Copy link
Contributor

@hi120ki hi120ki commented Aug 21, 2024

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"
)

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())
}

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 <[email protected]>
Copy link

google-cla bot commented Aug 21, 2024

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
Collaborator

gmlewis commented Aug 21, 2024

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

Copy link

codecov bot commented Aug 21, 2024

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 <[email protected]>
@gmlewis gmlewis changed the title Add : Organization PAT installation Add Organization PAT fields to InstallationPermissions struct Aug 21, 2024
Copy link
Collaborator

@gmlewis gmlewis left a comment

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:master Aug 21, 2024
6 of 7 checks passed
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.

2 participants