Skip to content

Commit

Permalink
Code cleanup (#455)
Browse files Browse the repository at this point in the history
* Don't do go mod vendor anymore

* Update create access key to move description next to name

* Add missing test coverage for 100%

* Add compilation warning for missing methods in management implementations

* Fix symbol visibility for SSOApplications
  • Loading branch information
shilgapira committed Aug 7, 2024
1 parent 0eab170 commit 8a6c2c5
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ help: ## This help
.DEFAULT_GOAL := help

build: ## Build package
go mod tidy && go mod vendor && go build ./...
go mod tidy && go build ./...
run-example: ## Run example web application
cd examples/webapp && go mod tidy && go mod vendor && go run main.go
cd examples/webapp && go mod tidy && go run main.go
run-gin-example: ## Run example web application
cd examples/ginwebapp && go mod tidy && go mod vendor && go run main.go
cd examples/ginwebapp && go mod tidy && go run main.go
4 changes: 2 additions & 2 deletions descope/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,11 +1148,11 @@ func NewClient(conf ClientParams) *Client {
} else {
// App has set a different transport layer, we will not change its attributes, and use it as is
// this will include the tls config
rt = http.DefaultTransport
rt = http.DefaultTransport // notest
}
var timeout = time.Second * 60
if conf.RequestTimeout != 0 {
timeout = conf.RequestTimeout
timeout = conf.RequestTimeout // notest
}
httpClient = &http.Client{
Timeout: timeout,
Expand Down
2 changes: 1 addition & 1 deletion descope/internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (auth *authenticationService) ExchangeAccessKey(ctx context.Context, access
}

tokens, err := auth.extractTokens(jwtResponse)
if err != nil {
if err != nil { // notest
errMsg := err.Error()
if len(errMsg) == 0 {
errMsg = "Missing token in JWT response"
Expand Down
5 changes: 4 additions & 1 deletion descope/internal/mgmt/accesskey.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type accessKey struct {
managementBase
}

func (a *accessKey) Create(ctx context.Context, name string, expireTime int64, roleNames []string, keyTenants []*descope.AssociatedTenant, userID string, customClaims map[string]any, description string, permittedIPs []string) (string, *descope.AccessKeyResponse, error) {
var _ sdk.AccessKey = &accessKey{}

func (a *accessKey) Create(ctx context.Context, name string, description string, expireTime int64, roleNames []string, keyTenants []*descope.AssociatedTenant, userID string, customClaims map[string]any, permittedIPs []string) (string, *descope.AccessKeyResponse, error) {
if name == "" {
return "", nil, utils.NewInvalidArgumentError("name")
}
Expand Down
4 changes: 2 additions & 2 deletions descope/internal/mgmt/accesskey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAccessKeyCreateSuccess(t *testing.T) {
require.Equal(t, "10.0.0.1", permittedIPs[0])
}, response))
cc := map[string]any{"k1": "v1"}
cleartext, key, err := mgmt.AccessKey().Create(context.Background(), "abc", 0, []string{"foo"}, nil, "uid", cc, desc, []string{"10.0.0.1"})
cleartext, key, err := mgmt.AccessKey().Create(context.Background(), "abc", desc, 0, []string{"foo"}, nil, "uid", cc, []string{"10.0.0.1"})
require.NoError(t, err)
require.Equal(t, "cleartext", cleartext)
require.Equal(t, "abc", key.Name)
Expand All @@ -49,7 +49,7 @@ func TestAccessKeyCreateSuccess(t *testing.T) {

func TestAccessKeyCreateError(t *testing.T) {
mgmt := newTestMgmt(nil, helpers.DoOk(nil))
_, _, err := mgmt.AccessKey().Create(context.Background(), "", 0, nil, nil, "", nil, "", nil)
_, _, err := mgmt.AccessKey().Create(context.Background(), "", "", 0, nil, nil, "", nil, nil)
require.Error(t, err)
}

Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type audit struct {
managementBase
}

var _ sdk.Audit = &audit{}

func (a *audit) Search(ctx context.Context, options *descope.AuditSearchOptions) ([]*descope.AuditRecord, error) {
body := map[string]any{
"userIds": options.UserIDs,
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type authz struct {
managementBase
}

var _ sdk.Authz = &authz{}

func (a *authz) SaveSchema(ctx context.Context, schema *descope.AuthzSchema, upgrade bool) error {
if schema == nil {
return utils.NewInvalidArgumentError("schema")
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type flow struct {
managementBase
}

var _ sdk.Flow = &flow{}

func (r *flow) ListFlows(ctx context.Context) (*descope.FlowsResponse, error) {
res, err := r.client.DoPostRequest(ctx, api.Routes.ManagementListFlows(), nil, nil, r.conf.ManagementKey)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type group struct {
managementBase
}

var _ sdk.Group = &group{}

func (r *group) LoadAllGroups(ctx context.Context, tenantID string) ([]*descope.Group, error) {
if tenantID == "" {
return nil, utils.NewInvalidArgumentError("tenantID")
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (

"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type jwt struct {
managementBase
}

var _ sdk.JWT = &jwt{}

type jwtRes struct {
JWT string `json:"jwt,omitempty"`
}
Expand Down
4 changes: 2 additions & 2 deletions descope/internal/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewManagement(conf ManagementParams, c *api.Client) *managementService {
base := managementBase{conf: &conf, client: c}
service := &managementService{managementBase: base}
service.tenant = &tenant{managementBase: base}
service.ssoApplication = &SSOApplication{managementBase: base}
service.ssoApplication = &ssoApplication{managementBase: base}
service.user = &user{managementBase: base}
service.accessKey = &accessKey{managementBase: base}
service.sso = &sso{managementBase: base}
Expand All @@ -52,7 +52,7 @@ func NewManagement(conf ManagementParams, c *api.Client) *managementService {
service.project = &project{managementBase: base}
service.audit = &audit{managementBase: base}
service.authz = &authz{managementBase: base}
service.password = &password{managementBase: base}
service.password = &passwordManagement{managementBase: base}
return service
}

Expand Down
9 changes: 6 additions & 3 deletions descope/internal/mgmt/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type password struct {
type passwordManagement struct {
managementBase
}

func (s *password) GetSettings(ctx context.Context, tenantID string) (*descope.PasswordSettings, error) {
var _ sdk.PasswordManagement = &passwordManagement{}

func (s *passwordManagement) GetSettings(ctx context.Context, tenantID string) (*descope.PasswordSettings, error) {
req := &api.HTTPRequest{
QueryParams: map[string]string{"tenantId": tenantID},
}
Expand All @@ -23,7 +26,7 @@ func (s *password) GetSettings(ctx context.Context, tenantID string) (*descope.P
return unmarshalPasswordSettingsResponse(res)
}

func (s *password) ConfigureSettings(ctx context.Context, tenantID string, passwordSettings *descope.PasswordSettings) error {
func (s *passwordManagement) ConfigureSettings(ctx context.Context, tenantID string, passwordSettings *descope.PasswordSettings) error {
req := map[string]any{
"tenantId": tenantID,
"enabled": passwordSettings.Enabled,
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type permission struct {
managementBase
}

var _ sdk.Permission = &permission{}

func (p *permission) Create(ctx context.Context, name, description string) error {
if name == "" {
return utils.NewInvalidArgumentError("name")
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type project struct {
managementBase
}

var _ sdk.Project = &project{}

type updateProjectBody struct {
Name string `json:"name"`
}
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type role struct {
managementBase
}

var _ sdk.Role = &role{}

func (r *role) Create(ctx context.Context, name, description string, permissionNames []string, tenantID string) error {
if name == "" {
return utils.NewInvalidArgumentError("name")
Expand Down
3 changes: 3 additions & 0 deletions descope/internal/mgmt/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type sso struct {
managementBase
}

var _ sdk.SSO = &sso{}

func (s *sso) LoadSettings(ctx context.Context, tenantID string) (*descope.SSOTenantSettingsResponse, error) {
if tenantID == "" {
return nil, utils.NewInvalidArgumentError("tenantID")
Expand Down
19 changes: 11 additions & 8 deletions descope/internal/mgmt/ssoapplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type SSOApplication struct {
type ssoApplication struct {
managementBase
}

func (s *SSOApplication) CreateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) (id string, err error) {
var _ sdk.SSOApplication = &ssoApplication{}

func (s *ssoApplication) CreateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) (id string, err error) {
if appRequest == nil {
return "", utils.NewInvalidArgumentError("appRequest")
}
Expand All @@ -34,7 +37,7 @@ func (s *SSOApplication) CreateOIDCApplication(ctx context.Context, appRequest *
return res.ID, nil
}

func (s *SSOApplication) CreateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) (id string, err error) {
func (s *ssoApplication) CreateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) (id string, err error) {
if appRequest == nil {
return "", utils.NewInvalidArgumentError("appRequest")
}
Expand All @@ -56,7 +59,7 @@ func (s *SSOApplication) CreateSAMLApplication(ctx context.Context, appRequest *
return res.ID, nil
}

func (s *SSOApplication) UpdateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) error {
func (s *ssoApplication) UpdateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) error {
if appRequest == nil {
return utils.NewInvalidArgumentError("appRequest")
}
Expand All @@ -72,7 +75,7 @@ func (s *SSOApplication) UpdateOIDCApplication(ctx context.Context, appRequest *
return err
}

func (s *SSOApplication) UpdateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) error {
func (s *ssoApplication) UpdateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) error {
if appRequest == nil {
return utils.NewInvalidArgumentError("appRequest")
}
Expand All @@ -88,7 +91,7 @@ func (s *SSOApplication) UpdateSAMLApplication(ctx context.Context, appRequest *
return err
}

func (s *SSOApplication) Delete(ctx context.Context, id string) error {
func (s *ssoApplication) Delete(ctx context.Context, id string) error {
if id == "" {
return utils.NewInvalidArgumentError("id")
}
Expand All @@ -97,7 +100,7 @@ func (s *SSOApplication) Delete(ctx context.Context, id string) error {
return err
}

func (s *SSOApplication) Load(ctx context.Context, id string) (*descope.SSOApplication, error) {
func (s *ssoApplication) Load(ctx context.Context, id string) (*descope.SSOApplication, error) {
if id == "" {
return nil, utils.NewInvalidArgumentError("id")
}
Expand All @@ -111,7 +114,7 @@ func (s *SSOApplication) Load(ctx context.Context, id string) (*descope.SSOAppli
return unmarshalLoadSSOApplicationResponse(res)
}

func (s *SSOApplication) LoadAll(ctx context.Context) ([]*descope.SSOApplication, error) {
func (s *ssoApplication) LoadAll(ctx context.Context) ([]*descope.SSOApplication, error) {
res, err := s.client.DoGetRequest(ctx, api.Routes.ManagementSSOApplicationLoadAll(), nil, s.conf.ManagementKey)
if err != nil {
return nil, err
Expand Down
11 changes: 7 additions & 4 deletions descope/internal/mgmt/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"github.com/descope/go-sdk/descope"
"github.com/descope/go-sdk/descope/api"
"github.com/descope/go-sdk/descope/internal/utils"
"github.com/descope/go-sdk/descope/sdk"
)

type tenant struct {
managementBase
}

var _ sdk.Tenant = &tenant{}

func (t *tenant) Create(ctx context.Context, tenantRequest *descope.TenantRequest) (id string, err error) {
if tenantRequest == nil {
tenantRequest = &descope.TenantRequest{}
tenantRequest = &descope.TenantRequest{} // notest
}
return t.createWithID(ctx, "", tenantRequest)
}
Expand All @@ -24,7 +27,7 @@ func (t *tenant) CreateWithID(ctx context.Context, id string, tenantRequest *des
return utils.NewInvalidArgumentError("id")
}
if tenantRequest == nil {
tenantRequest = &descope.TenantRequest{}
tenantRequest = &descope.TenantRequest{} // notest
}
_, err := t.createWithID(ctx, id, tenantRequest)
return err
Expand Down Expand Up @@ -94,7 +97,7 @@ func (t *tenant) LoadAll(ctx context.Context) ([]*descope.Tenant, error) {
func (t *tenant) SearchAll(ctx context.Context, options *descope.TenantSearchOptions) ([]*descope.Tenant, error) {
// Init empty options if non given
if options == nil {
options = &descope.TenantSearchOptions{}
options = &descope.TenantSearchOptions{} // notest
}

req := makeSearchTenantRequest(options)
Expand All @@ -107,7 +110,7 @@ func (t *tenant) SearchAll(ctx context.Context, options *descope.TenantSearchOpt

func (t *tenant) GetSettings(ctx context.Context, tenantID string) (*descope.TenantSettings, error) {
if tenantID == "" {
return nil, utils.NewInvalidArgumentError("tenantID")
return nil, utils.NewInvalidArgumentError("tenantID") // notest
}
req := &api.HTTPRequest{
QueryParams: map[string]string{"id": tenantID},
Expand Down
Loading

0 comments on commit 8a6c2c5

Please sign in to comment.