Skip to content

Commit 8a6c2c5

Browse files
authored
Code cleanup (#455)
* 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
1 parent 0eab170 commit 8a6c2c5

24 files changed

+157
-42
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ help: ## This help
88
.DEFAULT_GOAL := help
99

1010
build: ## Build package
11-
go mod tidy && go mod vendor && go build ./...
11+
go mod tidy && go build ./...
1212
run-example: ## Run example web application
13-
cd examples/webapp && go mod tidy && go mod vendor && go run main.go
13+
cd examples/webapp && go mod tidy && go run main.go
1414
run-gin-example: ## Run example web application
15-
cd examples/ginwebapp && go mod tidy && go mod vendor && go run main.go
15+
cd examples/ginwebapp && go mod tidy && go run main.go

descope/api/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,11 @@ func NewClient(conf ClientParams) *Client {
11481148
} else {
11491149
// App has set a different transport layer, we will not change its attributes, and use it as is
11501150
// this will include the tls config
1151-
rt = http.DefaultTransport
1151+
rt = http.DefaultTransport // notest
11521152
}
11531153
var timeout = time.Second * 60
11541154
if conf.RequestTimeout != 0 {
1155-
timeout = conf.RequestTimeout
1155+
timeout = conf.RequestTimeout // notest
11561156
}
11571157
httpClient = &http.Client{
11581158
Timeout: timeout,

descope/internal/auth/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (auth *authenticationService) ExchangeAccessKey(ctx context.Context, access
391391
}
392392

393393
tokens, err := auth.extractTokens(jwtResponse)
394-
if err != nil {
394+
if err != nil { // notest
395395
errMsg := err.Error()
396396
if len(errMsg) == 0 {
397397
errMsg = "Missing token in JWT response"

descope/internal/mgmt/accesskey.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type accessKey struct {
1213
managementBase
1314
}
1415

15-
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) {
16+
var _ sdk.AccessKey = &accessKey{}
17+
18+
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) {
1619
if name == "" {
1720
return "", nil, utils.NewInvalidArgumentError("name")
1821
}

descope/internal/mgmt/accesskey_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAccessKeyCreateSuccess(t *testing.T) {
3636
require.Equal(t, "10.0.0.1", permittedIPs[0])
3737
}, response))
3838
cc := map[string]any{"k1": "v1"}
39-
cleartext, key, err := mgmt.AccessKey().Create(context.Background(), "abc", 0, []string{"foo"}, nil, "uid", cc, desc, []string{"10.0.0.1"})
39+
cleartext, key, err := mgmt.AccessKey().Create(context.Background(), "abc", desc, 0, []string{"foo"}, nil, "uid", cc, []string{"10.0.0.1"})
4040
require.NoError(t, err)
4141
require.Equal(t, "cleartext", cleartext)
4242
require.Equal(t, "abc", key.Name)
@@ -49,7 +49,7 @@ func TestAccessKeyCreateSuccess(t *testing.T) {
4949

5050
func TestAccessKeyCreateError(t *testing.T) {
5151
mgmt := newTestMgmt(nil, helpers.DoOk(nil))
52-
_, _, err := mgmt.AccessKey().Create(context.Background(), "", 0, nil, nil, "", nil, "", nil)
52+
_, _, err := mgmt.AccessKey().Create(context.Background(), "", "", 0, nil, nil, "", nil, nil)
5353
require.Error(t, err)
5454
}
5555

descope/internal/mgmt/audit.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import (
88
"github.com/descope/go-sdk/descope"
99
"github.com/descope/go-sdk/descope/api"
1010
"github.com/descope/go-sdk/descope/internal/utils"
11+
"github.com/descope/go-sdk/descope/sdk"
1112
)
1213

1314
type audit struct {
1415
managementBase
1516
}
1617

18+
var _ sdk.Audit = &audit{}
19+
1720
func (a *audit) Search(ctx context.Context, options *descope.AuditSearchOptions) ([]*descope.AuditRecord, error) {
1821
body := map[string]any{
1922
"userIds": options.UserIDs,

descope/internal/mgmt/authz.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import (
77
"github.com/descope/go-sdk/descope"
88
"github.com/descope/go-sdk/descope/api"
99
"github.com/descope/go-sdk/descope/internal/utils"
10+
"github.com/descope/go-sdk/descope/sdk"
1011
)
1112

1213
type authz struct {
1314
managementBase
1415
}
1516

17+
var _ sdk.Authz = &authz{}
18+
1619
func (a *authz) SaveSchema(ctx context.Context, schema *descope.AuthzSchema, upgrade bool) error {
1720
if schema == nil {
1821
return utils.NewInvalidArgumentError("schema")

descope/internal/mgmt/flow.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type flow struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Flow = &flow{}
17+
1518
func (r *flow) ListFlows(ctx context.Context) (*descope.FlowsResponse, error) {
1619
res, err := r.client.DoPostRequest(ctx, api.Routes.ManagementListFlows(), nil, nil, r.conf.ManagementKey)
1720
if err != nil {

descope/internal/mgmt/group.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type group struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Group = &group{}
17+
1518
func (r *group) LoadAllGroups(ctx context.Context, tenantID string) ([]*descope.Group, error) {
1619
if tenantID == "" {
1720
return nil, utils.NewInvalidArgumentError("tenantID")

descope/internal/mgmt/jwt.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import (
55

66
"github.com/descope/go-sdk/descope/api"
77
"github.com/descope/go-sdk/descope/internal/utils"
8+
"github.com/descope/go-sdk/descope/sdk"
89
)
910

1011
type jwt struct {
1112
managementBase
1213
}
1314

15+
var _ sdk.JWT = &jwt{}
16+
1417
type jwtRes struct {
1518
JWT string `json:"jwt,omitempty"`
1619
}

descope/internal/mgmt/mgmt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewManagement(conf ManagementParams, c *api.Client) *managementService {
4040
base := managementBase{conf: &conf, client: c}
4141
service := &managementService{managementBase: base}
4242
service.tenant = &tenant{managementBase: base}
43-
service.ssoApplication = &SSOApplication{managementBase: base}
43+
service.ssoApplication = &ssoApplication{managementBase: base}
4444
service.user = &user{managementBase: base}
4545
service.accessKey = &accessKey{managementBase: base}
4646
service.sso = &sso{managementBase: base}
@@ -52,7 +52,7 @@ func NewManagement(conf ManagementParams, c *api.Client) *managementService {
5252
service.project = &project{managementBase: base}
5353
service.audit = &audit{managementBase: base}
5454
service.authz = &authz{managementBase: base}
55-
service.password = &password{managementBase: base}
55+
service.password = &passwordManagement{managementBase: base}
5656
return service
5757
}
5858

descope/internal/mgmt/password.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

11-
type password struct {
12+
type passwordManagement struct {
1213
managementBase
1314
}
1415

15-
func (s *password) GetSettings(ctx context.Context, tenantID string) (*descope.PasswordSettings, error) {
16+
var _ sdk.PasswordManagement = &passwordManagement{}
17+
18+
func (s *passwordManagement) GetSettings(ctx context.Context, tenantID string) (*descope.PasswordSettings, error) {
1619
req := &api.HTTPRequest{
1720
QueryParams: map[string]string{"tenantId": tenantID},
1821
}
@@ -23,7 +26,7 @@ func (s *password) GetSettings(ctx context.Context, tenantID string) (*descope.P
2326
return unmarshalPasswordSettingsResponse(res)
2427
}
2528

26-
func (s *password) ConfigureSettings(ctx context.Context, tenantID string, passwordSettings *descope.PasswordSettings) error {
29+
func (s *passwordManagement) ConfigureSettings(ctx context.Context, tenantID string, passwordSettings *descope.PasswordSettings) error {
2730
req := map[string]any{
2831
"tenantId": tenantID,
2932
"enabled": passwordSettings.Enabled,

descope/internal/mgmt/permission.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type permission struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Permission = &permission{}
17+
1518
func (p *permission) Create(ctx context.Context, name, description string) error {
1619
if name == "" {
1720
return utils.NewInvalidArgumentError("name")

descope/internal/mgmt/project.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type project struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Project = &project{}
17+
1518
type updateProjectBody struct {
1619
Name string `json:"name"`
1720
}

descope/internal/mgmt/role.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type role struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Role = &role{}
17+
1518
func (r *role) Create(ctx context.Context, name, description string, permissionNames []string, tenantID string) error {
1619
if name == "" {
1720
return utils.NewInvalidArgumentError("name")

descope/internal/mgmt/sso.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type sso struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.SSO = &sso{}
17+
1518
func (s *sso) LoadSettings(ctx context.Context, tenantID string) (*descope.SSOTenantSettingsResponse, error) {
1619
if tenantID == "" {
1720
return nil, utils.NewInvalidArgumentError("tenantID")

descope/internal/mgmt/ssoapplication.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

11-
type SSOApplication struct {
12+
type ssoApplication struct {
1213
managementBase
1314
}
1415

15-
func (s *SSOApplication) CreateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) (id string, err error) {
16+
var _ sdk.SSOApplication = &ssoApplication{}
17+
18+
func (s *ssoApplication) CreateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) (id string, err error) {
1619
if appRequest == nil {
1720
return "", utils.NewInvalidArgumentError("appRequest")
1821
}
@@ -34,7 +37,7 @@ func (s *SSOApplication) CreateOIDCApplication(ctx context.Context, appRequest *
3437
return res.ID, nil
3538
}
3639

37-
func (s *SSOApplication) CreateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) (id string, err error) {
40+
func (s *ssoApplication) CreateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) (id string, err error) {
3841
if appRequest == nil {
3942
return "", utils.NewInvalidArgumentError("appRequest")
4043
}
@@ -56,7 +59,7 @@ func (s *SSOApplication) CreateSAMLApplication(ctx context.Context, appRequest *
5659
return res.ID, nil
5760
}
5861

59-
func (s *SSOApplication) UpdateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) error {
62+
func (s *ssoApplication) UpdateOIDCApplication(ctx context.Context, appRequest *descope.OIDCApplicationRequest) error {
6063
if appRequest == nil {
6164
return utils.NewInvalidArgumentError("appRequest")
6265
}
@@ -72,7 +75,7 @@ func (s *SSOApplication) UpdateOIDCApplication(ctx context.Context, appRequest *
7275
return err
7376
}
7477

75-
func (s *SSOApplication) UpdateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) error {
78+
func (s *ssoApplication) UpdateSAMLApplication(ctx context.Context, appRequest *descope.SAMLApplicationRequest) error {
7679
if appRequest == nil {
7780
return utils.NewInvalidArgumentError("appRequest")
7881
}
@@ -88,7 +91,7 @@ func (s *SSOApplication) UpdateSAMLApplication(ctx context.Context, appRequest *
8891
return err
8992
}
9093

91-
func (s *SSOApplication) Delete(ctx context.Context, id string) error {
94+
func (s *ssoApplication) Delete(ctx context.Context, id string) error {
9295
if id == "" {
9396
return utils.NewInvalidArgumentError("id")
9497
}
@@ -97,7 +100,7 @@ func (s *SSOApplication) Delete(ctx context.Context, id string) error {
97100
return err
98101
}
99102

100-
func (s *SSOApplication) Load(ctx context.Context, id string) (*descope.SSOApplication, error) {
103+
func (s *ssoApplication) Load(ctx context.Context, id string) (*descope.SSOApplication, error) {
101104
if id == "" {
102105
return nil, utils.NewInvalidArgumentError("id")
103106
}
@@ -111,7 +114,7 @@ func (s *SSOApplication) Load(ctx context.Context, id string) (*descope.SSOAppli
111114
return unmarshalLoadSSOApplicationResponse(res)
112115
}
113116

114-
func (s *SSOApplication) LoadAll(ctx context.Context) ([]*descope.SSOApplication, error) {
117+
func (s *ssoApplication) LoadAll(ctx context.Context) ([]*descope.SSOApplication, error) {
115118
res, err := s.client.DoGetRequest(ctx, api.Routes.ManagementSSOApplicationLoadAll(), nil, s.conf.ManagementKey)
116119
if err != nil {
117120
return nil, err

descope/internal/mgmt/tenant.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import (
66
"github.com/descope/go-sdk/descope"
77
"github.com/descope/go-sdk/descope/api"
88
"github.com/descope/go-sdk/descope/internal/utils"
9+
"github.com/descope/go-sdk/descope/sdk"
910
)
1011

1112
type tenant struct {
1213
managementBase
1314
}
1415

16+
var _ sdk.Tenant = &tenant{}
17+
1518
func (t *tenant) Create(ctx context.Context, tenantRequest *descope.TenantRequest) (id string, err error) {
1619
if tenantRequest == nil {
17-
tenantRequest = &descope.TenantRequest{}
20+
tenantRequest = &descope.TenantRequest{} // notest
1821
}
1922
return t.createWithID(ctx, "", tenantRequest)
2023
}
@@ -24,7 +27,7 @@ func (t *tenant) CreateWithID(ctx context.Context, id string, tenantRequest *des
2427
return utils.NewInvalidArgumentError("id")
2528
}
2629
if tenantRequest == nil {
27-
tenantRequest = &descope.TenantRequest{}
30+
tenantRequest = &descope.TenantRequest{} // notest
2831
}
2932
_, err := t.createWithID(ctx, id, tenantRequest)
3033
return err
@@ -94,7 +97,7 @@ func (t *tenant) LoadAll(ctx context.Context) ([]*descope.Tenant, error) {
9497
func (t *tenant) SearchAll(ctx context.Context, options *descope.TenantSearchOptions) ([]*descope.Tenant, error) {
9598
// Init empty options if non given
9699
if options == nil {
97-
options = &descope.TenantSearchOptions{}
100+
options = &descope.TenantSearchOptions{} // notest
98101
}
99102

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

108111
func (t *tenant) GetSettings(ctx context.Context, tenantID string) (*descope.TenantSettings, error) {
109112
if tenantID == "" {
110-
return nil, utils.NewInvalidArgumentError("tenantID")
113+
return nil, utils.NewInvalidArgumentError("tenantID") // notest
111114
}
112115
req := &api.HTTPRequest{
113116
QueryParams: map[string]string{"id": tenantID},

0 commit comments

Comments
 (0)