Skip to content

Commit

Permalink
Merge branch 'master' into clientid-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestelfer committed Jun 2, 2024
2 parents 1438121 + d680810 commit b705bd9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 36 deletions.
23 changes: 19 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
groups:
gomod:
update-types:
- "patch"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
groups:
actions:
update-types:
- "minor"
- "patch"
14 changes: 10 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
go-version: ['1.21', '1.22']

steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.17
go-version: ${{ matrix.go-version }}
check-latest: true

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Get dependencies
run: go get -v -t -d ./...
Expand Down
7 changes: 3 additions & 4 deletions appsTransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/rsa"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
"time"

Expand Down Expand Up @@ -179,10 +179,9 @@ func WithClientID(clientID string) AppsTransportOptionError {

func WithPrivateKeyFile(privateKeyFile string) AppsTransportOptionError {
return func(at *AppsTransport) error {
// deprecated function kept for go 1.13 compatibility
privateKey, err := ioutil.ReadFile(privateKeyFile)
privateKey, err := os.ReadFile(privateKeyFile)
if err != nil {
return fmt.Errorf("could not read private key: %w", err)
return fmt.Errorf("could not read private key: %s", err)
}

return WithPrivateKeyRaw(privateKey)(at)
Expand Down
9 changes: 4 additions & 5 deletions appsTransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ghinstallation
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -15,7 +14,7 @@ import (
)

func TestNewAppsTransportKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestJWTExpiry(t *testing.T) {
check := RoundTrip{
rt: func(req *http.Request) (*http.Response, error) {
token := strings.Fields(req.Header.Get("Authorization"))[1]
tok, err := jwt.ParseWithClaims(token, &jwt.StandardClaims{}, func(t *jwt.Token) (interface{}, error) {
tok, err := jwt.ParseWithClaims(token, &jwt.RegisteredClaims{}, func(t *jwt.Token) (interface{}, error) {
if t.Header["alg"] != "RS256" {
return nil, fmt.Errorf("unexpected signing method: %v, expected: %v", t.Header["alg"], "RS256")
}
Expand All @@ -94,8 +93,8 @@ func TestJWTExpiry(t *testing.T) {
t.Fatalf("jwt parse: %v", err)
}

c := tok.Claims.(*jwt.StandardClaims)
if c.ExpiresAt == 0 {
c := tok.Claims.(*jwt.RegisteredClaims)
if c.ExpiresAt.IsZero() {
t.Fatalf("missing exp claim")
}
return nil, nil
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module github.com/bradleyfalzon/ghinstallation/v2

go 1.13
go 1.16

require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v61 v61.0.0
github.com/google/go-github/v62 v62.0.0
)

require github.com/google/go-querystring v1.1.0 // indirect
require (
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go=
github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY=
github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4=
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 3 additions & 3 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"

"github.com/google/go-github/v61/github"
"github.com/google/go-github/v62/github"
)

const (
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ http.RoundTripper = &Transport{}

// NewKeyFromFile returns a Transport using a private key from file.
func NewKeyFromFile(tr http.RoundTripper, appID, installationID int64, privateKeyFile string) (*Transport, error) {
privateKey, err := ioutil.ReadFile(privateKeyFile)
privateKey, err := os.ReadFile(privateKeyFile)
if err != nil {
return nil, fmt.Errorf("could not read private key: %s", err)
}
Expand Down
22 changes: 11 additions & 11 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -15,7 +15,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-github/v61/github"
"github.com/google/go-github/v62/github"
)

const (
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestNew(t *testing.T) {
}

func TestNewKeyFromFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -226,8 +226,8 @@ func TestRefreshTokenWithParameters(t *testing.T) {
rt: func(req *http.Request) (*http.Response, error) {
// Convert io.ReadCloser to String without deleting body data.
var gotBodyBytes []byte
gotBodyBytes, _ = ioutil.ReadAll(req.Body)
req.Body = ioutil.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyBytes, _ = io.ReadAll(req.Body)
req.Body = io.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyString := string(gotBodyBytes)

// Compare request sent with request received.
Expand All @@ -251,7 +251,7 @@ func TestRefreshTokenWithParameters(t *testing.T) {
if err != nil {
return nil, fmt.Errorf("error converting token into io.ReadWriter: %+v", err)
}
tokenBody := ioutil.NopCloser(tokenReadWriter)
tokenBody := io.NopCloser(tokenReadWriter)
return &http.Response{
Body: tokenBody,
StatusCode: 200,
Expand Down Expand Up @@ -295,22 +295,22 @@ func TestRefreshTokenWithTrailingSlashBaseURL(t *testing.T) {
rt: func(req *http.Request) (*http.Response, error) {
if strings.Contains(req.URL.Path, "//") {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader("Forbidden\n")),
Body: io.NopCloser(strings.NewReader("Forbidden\n")),
StatusCode: 401,
}, fmt.Errorf("Got simulated 401 Github Forbidden response")
}

if req.URL.Path == "test_endpoint/" && req.Header.Get("Authorization") == fmt.Sprintf("token %s", tokenToBe) {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader("Beautiful\n")),
Body: io.NopCloser(strings.NewReader("Beautiful\n")),
StatusCode: 200,
}, nil
}

// Convert io.ReadCloser to String without deleting body data.
var gotBodyBytes []byte
gotBodyBytes, _ = ioutil.ReadAll(req.Body)
req.Body = ioutil.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyBytes, _ = io.ReadAll(req.Body)
req.Body = io.NopCloser(bytes.NewBuffer(gotBodyBytes))
gotBodyString := string(gotBodyBytes)

// Compare request sent with request received.
Expand All @@ -334,7 +334,7 @@ func TestRefreshTokenWithTrailingSlashBaseURL(t *testing.T) {
if err != nil {
return nil, fmt.Errorf("error converting token into io.ReadWriter: %+v", err)
}
tokenBody := ioutil.NopCloser(tokenReadWriter)
tokenBody := io.NopCloser(tokenReadWriter)
return &http.Response{
Body: tokenBody,
StatusCode: 200,
Expand Down

0 comments on commit b705bd9

Please sign in to comment.