+
Skip to content

Add organization secret API support #1535

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

Merged
merged 3 commits into from
May 28, 2020

Conversation

nightlark
Copy link
Contributor

Related to #1525 and #1532.

Adds organization secrets https://developer.github.com/v3/actions/secrets/#get-an-organization-public-key and updates the repository secret actions API (probably would match how they would be named if org support had been in from the beginning, though it would be considered a breaking change).

Some possible issues:

  • Checking with GitHub support if parameter selected repository ids should be an array of integers instead of array of strings. I think its been ~1 week?
  • Naming of the functions using the API endpoint header results in very long names.
  • Handling of extra values in Secret and EncryptedSecret for organization secrets that repository secrets don't have: does omitempty make sense or should they be separate structs?
  • Should there be an underlying function used for both organization and repository secrets that takes the base url as an argument? Quite a bit of duplication.
  • Repository id (and id array) argument using int64 (or int64[]), or use the Repository type for the argument?
  • Handling of selected repository IDs parameter as a type that wraps int64[], so that it gets marshaled to json correctly for SetSelectedRepositoriesForOrganizationSecret or is there a cleaner way to do this and use int64[] directly?

@googlebot googlebot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label May 22, 2020
@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #1535 into master will decrease coverage by 0.15%.
The diff coverage is 58.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1535      +/-   ##
==========================================
- Coverage   68.03%   67.87%   -0.16%     
==========================================
  Files          94       94              
  Lines        8528     8654     +126     
==========================================
+ Hits         5802     5874      +72     
- Misses       1844     1880      +36     
- Partials      882      900      +18     
Impacted Files Coverage Δ
github/actions_secrets.go 54.00% <58.00%> (+2.21%) ⬆️
github/actions_workflow_runs.go 57.57% <0.00%> (-0.57%) ⬇️
github/actions_workflows.go 61.11% <0.00%> (+3.96%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45c5021...48c5e83. Read the comment docs.

@cj-taylor cj-taylor mentioned this pull request May 22, 2020
9 tasks
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.

This is looking great, @nightlark ! Thank you for all the research and obvious effort that you have put into this... I really like it.

I've made a few suggestions, please let me know what you think.

@@ -92,6 +113,11 @@ func (s *ActionsService) GetSecret(ctx context.Context, owner, repo, name string
return secret, resp, nil
}

// SelectedRepositoryIDs are the repository IDs that have access to the secret.
type SelectedRepositoryIDs struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of making this a struct, how about if we make it a type so that it can be used more easily both within a response and as a request parameter?

type SelectedRepoIDs []int64

@@ -101,12 +127,14 @@ type EncryptedSecret struct {
Name string `json:"-"`
KeyID string `json:"key_id"`
EncryptedValue string `json:"encrypted_value"`
Visibility string `json:"visibility,omitempty"`
SelectedRepositoryIDs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Then this would become:

SelectedRepositoryIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`

Note the long field name to correspond to the long JSON parameter name but the shorter type name.

@@ -16,10 +16,10 @@ type PublicKey struct {
Key *string `json:"key"`
}

// GetPublicKey gets a public key that should be used for secret encryption.
// GetRepositoryPublicKey gets a public key that should be used for secret encryption.
Copy link
Collaborator

Choose a reason for hiding this comment

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

When names get impractically long (not that this one is, but down below... and you mentioned it in the issue),
in other places in this repo we have chosen to shorten "Repository" to "Repo" and "Organization" to "Org".

I think that would work well here... but let's go through these modified files and be consistent with the renaming since this is a breaking-API-change PR anyway.

So this would be GetRepoPublicKey.

@@ -35,11 +35,32 @@ func (s *ActionsService) GetPublicKey(ctx context.Context, owner, repo string) (
return pubKey, resp, nil
}

// GetOrganizationPublicKey gets a public key that should be used for secret encryption.
Copy link
Collaborator

Choose a reason for hiding this comment

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

GetOrgPublicKey

@@ -48,12 +69,12 @@ type Secrets struct {
Secrets []*Secret `json:"secrets"`
}

// ListSecrets lists all secrets available in a repository
// ListRepositorySecrets lists all secrets available in a repository
Copy link
Collaborator

Choose a reason for hiding this comment

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

ListRepoSecrets

return result, resp, nil
}

// SetSelectedRepositoriesForOrganizationSecret sets the repositories that have access to a secret.
Copy link
Collaborator

Choose a reason for hiding this comment

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

SetSelectedReposForOrgSecret

return s.client.Do(ctx, req, nil)
}

// AddSelectedRepositoryToOrganizationSecret adds a repository to an organization secret.
Copy link
Collaborator

Choose a reason for hiding this comment

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

AddSelectedRepoToOrgSecret

return s.client.Do(ctx, req, nil)
}

// RemoveSelectedRepositoryFromOrganizationSecret removes a repository from an organization secret.
Copy link
Collaborator

Choose a reason for hiding this comment

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

RemoveSelectedRepoFromOrgSecret

// GitHub API docs: https://developer.github.com/v3/actions/secrets/#set-selected-repositories-for-an-organization-secret
func (s *ActionsService) SetSelectedRepositoriesForOrganizationSecret(ctx context.Context, org, name string, ids SelectedRepositoryIDs) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name)
req, err := s.client.NewRequest("PUT", u, ids)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because of my type ... []int64 suggestion above, you will have to wrap this into a private struct with the appropriate json tag to make this work again... but I think it still makes the API cleaner and easier for users of this repo, so I think it is a better way to go.

return s.client.Do(ctx, req, nil)
}

// DeleteOrganizationSecret deletes a secret in an organization using the secret name.
Copy link
Collaborator

Choose a reason for hiding this comment

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

DeleteOrgSecret

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, @nightlark!
LGTM.

Awaiting second LGTM before merging.

@gmlewis gmlewis requested review from gauntface and wesleimp May 23, 2020 19:25
Copy link
Collaborator

@wesleimp wesleimp left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@gmlewis gmlewis added the Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). label May 28, 2020
@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

Thank you, @wesleimp!
Merging.

@gmlewis gmlewis merged commit 8d28b93 into google:master May 28, 2020
@z0mbix
Copy link

z0mbix commented May 28, 2020

Thanks for all the work on this, any idea when this may get released?

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

We could put together a release today.
(We switched to an on-demand model.)

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

Could you, @z0mbix or you, @andrew-waters please review #1534 for me to get the one outstanding breaking API change into the release before I bump the major version again? Thank you!

@andrew-waters
Copy link

I'm unable to review here @gmlewis, I'm not a maintainer - I'm here for https://github.com/terraform-providers/terraform-provider-github/issues/468

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

Thank you, @andrew-waters - just to clarify, this repo is completely run by volunteers and all our code reviewers are Go programmers who are also volunteers. So I welcome your reviews, as that would help me unblock this next release. 😄

@z0mbix
Copy link

z0mbix commented May 28, 2020

LGTM, I’ve approved it.

@andrew-waters
Copy link

Ah ok, thanks @gmlewis - I hadn't realised and didn't fancy stepping on toes here 😄 . I've added a second approval too

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

@z0mbix - we have now released v32: https://github.com/google/go-github/releases/tag/v32.0.0
Thanks for your help, everyone.

@z0mbix
Copy link

z0mbix commented May 28, 2020

Thank you! 🙇

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

You're welcome! Now, if we could just get the Go proxy to recognize it so we can start using it!

https://pkg.go.dev/mod/github.com/google/go-github/v32
https://proxy.golang.org/github.com/google/go-github/v32/@v/v32.0.0.info

@gmlewis
Copy link
Collaborator

gmlewis commented May 28, 2020

OK, go get just started working. So it looks like the Go proxy takes about 30 minutes to ingest a new release. Good to know. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载