Repository navigation
Closed
Description
Hello,
I believe there was a regression in #2794.
Documentation of organization secrets expects a string but we're now sending integers.
This in turn causes a failure when calling the API.
I think the issue lies in that "setting" repository ids is done via integers on the API (REF), while creating or updating a secrets expects repository ids to be a string (REF). So they cannot have the same underlying type in the client as long as the API expected different types
Sample Go Code
package main
import (
"context"
"encoding/base64"
"fmt"
"log"
"os"
"github.com/google/go-github/v53/github"
"golang.org/x/crypto/nacl/box"
"golang.org/x/oauth2"
)
func main() {
ctx := context.Background()
if err := run(ctx); err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context) error {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_API_TOKEN")},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
org := os.Getenv("GITHUB_OWNER")
pubKey, _, err := client.Dependabot.GetOrgPublicKey(ctx, org)
if err != nil {
return err
}
enc, err := encryptPlaintext("SECRET", *pubKey.Key)
if err != nil {
return err
}
_, err = client.Dependabot.CreateOrUpdateOrgSecret(ctx, org, &github.DependabotEncryptedSecret{
Name: "EXAMPLE",
KeyID: *pubKey.KeyID,
EncryptedValue: base64.StdEncoding.EncodeToString(enc),
SelectedRepositoryIDs: []int64{123456789},
Visibility: "selected",
})
return err
}
func encryptPlaintext(plaintext, publicKeyB64 string) ([]byte, error) {
publicKeyBytes, err := base64.StdEncoding.DecodeString(publicKeyB64)
if err != nil {
return nil, err
}
var publicKeyBytes32 [32]byte
copiedLen := copy(publicKeyBytes32[:], publicKeyBytes)
if copiedLen == 0 {
return nil, fmt.Errorf("could not convert publicKey to bytes")
}
plaintextBytes := []byte(plaintext)
var encryptedBytes []byte
cipherText, err := box.SealAnonymous(encryptedBytes, plaintextBytes, &publicKeyBytes32, nil)
if err != nil {
return nil, err
}
return cipherText, nil
}Sample Output
2023/06/22 09:52:26 PUT https://api.github.com/orgs/<my-org>/dependabot/secrets/EXAMPLE: 422 Invalid request.
Invalid property /selected_repository_ids/0: `123456789` is not of type `string`. []
exit status 1Metadata
Metadata
Assignees
Labels
No labels
Activity
gmlewis commentedon Jun 22, 2023
It looks like we are talking about two different endpoints. The first one takes an array of integers, and the second takes an array of strings:
It looks like we need two separate ways of representing the requests for these two endpoints.
@frankywahl - do you want to submit a PR, or should I open this up to other contributors to this repo?
Fix `CreateOrUpdateOrgSecret` regression introduced in v53 (#2817)
Fix `CreateOrUpdateOrgSecret` regression introduced in v53 (google#2817)