From ee8869fd3373691fa06f66a89f20ca67ba15e654 Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Wed, 7 Sep 2022 11:48:21 -0400 Subject: [PATCH] release: v0.0.3 - Fix incorrectly applying client_credentials validation to api_token cred method [openfga/sdk-generator#21](https://github.com/openfga/sdk-generator/pull/21) - Target go 1.19 - Bump golang.org/x/net - Use [govulncheck](https://go.dev/blog/vuln) in CI to check for issues --- .github/workflows/main.yaml | 12 ++++++++--- CHANGELOG.md | 9 ++++++++ configuration.go | 2 +- credentials/credentials.go | 2 +- fga_test.go | 43 +++++++++++++++++++++++++++++++++++++ go.mod | 4 ++-- go.sum | 4 ++-- 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 90a30a1..0f2beca 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -13,7 +13,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 cache: true - name: Build run: go build -v ./... @@ -39,7 +39,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 cache: true - name: Build run: go build -v ./... @@ -59,7 +59,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 - name: Build run: go build -v ./... @@ -67,6 +67,12 @@ jobs: - name: Test run: go test -v ./... + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@latest + + - name: Run govulncheck + run: govulncheck ./... + create-release: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a080e9..54d0f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v0.0.3 + +### [0.0.3](https://github.com/openfga/go-sdk/compare/v0.0.2...v0.0.3) (2022-09-07) + +- Fix incorrectly applying client_credentials validation to api_token cred method [openfga/sdk-generator#21](https://github.com/openfga/sdk-generator/pull/21) +- Target go 1.19 +- Bump golang.org/x/net +- Use [govulncheck](https://go.dev/blog/vuln) in CI to check for issues + ## v0.0.2 ### [0.0.2](https://github.com/openfga/go-sdk/compare/v0.0.1...v0.0.2) (2022-08-15) diff --git a/configuration.go b/configuration.go index 65b9a57..15a5886 100644 --- a/configuration.go +++ b/configuration.go @@ -19,7 +19,7 @@ import ( "github.com/openfga/go-sdk/credentials" ) -var SdkVersion = "0.0.2" +var SdkVersion = "0.0.3" // RetryParams configures configuration for retry in case of HTTP too many request type RetryParams struct { diff --git a/credentials/credentials.go b/credentials/credentials.go index c37ac34..305f004 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -70,7 +70,7 @@ func (c *Credentials) ValidateCredentialsConfig() error { conf := c.Config if c.Method == CredentialsMethodApiToken && (conf == nil || conf.ApiToken == "") { return fmt.Errorf("CredentialsConfig.ApiToken is required when CredentialsMethod is CredentialsMethodApiToken (%s)", c.Method) - } else if c.Method == CredentialsMethodApiToken { + } else if c.Method == CredentialsMethodClientCredentials { if conf == nil || conf.ClientCredentialsClientId == "" || conf.ClientCredentialsClientSecret == "" || diff --git a/fga_test.go b/fga_test.go index 19bfa4d..faeee80 100644 --- a/fga_test.go +++ b/fga_test.go @@ -85,6 +85,49 @@ func TestOpenFgaApiConfiguration(t *testing.T) { } }) + t.Run("should issue a successful network call when using ApiToken credential method", func(t *testing.T) { + configuration, err := NewConfiguration(Configuration{ + ApiHost: "api.fga.example", + StoreId: "6c181474-aaa1-4df7-8929-6e7b3a992754", + Credentials: &credentials.Credentials{ + Method: credentials.CredentialsMethodApiToken, + Config: &credentials.Config{ + ApiToken: "some-token", + }, + }, + }) + if err != nil { + t.Fatalf("%v", err) + } + + apiClient := NewAPIClient(configuration) + + httpmock.Activate() + defer httpmock.DeactivateAndReset() + httpmock.RegisterResponder("GET", fmt.Sprintf("%s://%s/stores/%s/authorization-models", configuration.ApiScheme, configuration.ApiHost, configuration.StoreId), + func(req *http.Request) (*http.Response, error) { + resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: &[]AuthorizationModel{ + { + Id: PtrString("1uHxCSuTP0VKPYSnkq1pbb1jeZw"), + TypeDefinitions: &[]TypeDefinition{}, + }, + { + Id: PtrString("GtQpMohWezFmIbyXxVEocOCxxgq"), + TypeDefinitions: &[]TypeDefinition{}, + }, + }}) + if err != nil { + return httpmock.NewStringResponse(500, ""), nil + } + return resp, nil + }, + ) + + if _, _, err = apiClient.OpenFgaApi.ReadAuthorizationModels(context.Background()).Execute(); err != nil { + t.Fatalf("%v", err) + } + }) + t.Run("In ClientCredentials method, providing no client id, secret, audience or issuer should error", func(t *testing.T) { _, err := NewConfiguration(Configuration{ ApiHost: "https://api.fga.example", diff --git a/go.mod b/go.mod index 0452adb..44620ce 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/openfga/go-sdk -go 1.18 +go 1.19 require ( github.com/jarcoal/httpmock v1.2.0 - golang.org/x/net v0.0.0-20220812174116-3211cb980234 + golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 ) diff --git a/go.sum b/go.sum index 9679bb1..1023fdd 100644 --- a/go.sum +++ b/go.sum @@ -2,5 +2,5 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc= github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk= github.com/maxatome/go-testdeep v1.11.0 h1:Tgh5efyCYyJFGUYiT0qxBSIDeXw0F5zSoatlou685kk= -golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= -golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 h1:1WGATo9HAhkWMbfyuVU0tEFP88OIkUvwaHFveQPvzCQ= +golang.org/x/net v0.0.0-20220907135653-1e95f45603a7/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=