Skip to content

Commit fbdb0ae

Browse files
authored
Linting fixes 21 4 (#1553)
1 parent 015006a commit fbdb0ae

35 files changed

+86
-105
lines changed

gateway/config/resource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const (
8080
// ResourceCluster is a resource
8181
ResourceCluster Resource = "cluster"
8282

83-
// ResourceLicense is a resource
83+
// ResourceCacheConfig is a resource
8484
ResourceCacheConfig Resource = "cache-config"
8585

8686
// ResourceDeployService is a resource

gateway/config/routing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ type Route struct {
4949
Source RouteSource `json:"source" yaml:"source" mapstructure:"source"`
5050
Targets []RouteTarget `json:"targets" yaml:"targets" mapstructure:"targets"`
5151
Rule *Rule `json:"rule" yaml:"rule" mapstructure:"rule"`
52-
IsRouteCacheable bool `json:"isRouteCacheable" yaml:"isRouteCacheable" mapstructure:"isRouteCacheable`
53-
CacheOptions []string `json:"cacheOptions" yaml:"cacheOptions" mapstructure:"cacheOptions`
52+
IsRouteCacheable bool `json:"isRouteCacheable" yaml:"isRouteCacheable" mapstructure:"isRouteCacheable"`
53+
CacheOptions []string `json:"cacheOptions" yaml:"cacheOptions" mapstructure:"cacheOptions"`
5454
Modify struct {
5555
Tmpl TemplatingEngine `json:"template,omitempty" yaml:"template,omitempty" mapstructure:"template"`
5656
ReqTmpl string `json:"requestTemplate" yaml:"requestTemplate" mapstructure:"requestTemplate"`

gateway/managers/admin/admin.go

+3
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ func New(nodeID, clusterID string, isDev bool, adminUserInfo *config.AdminUser)
3636
return m
3737
}
3838

39+
// SetSyncMan sets syncman manager
3940
func (m *Manager) SetSyncMan(s model.SyncManAdminInterface) {
4041
m.lock.Lock()
4142
defer m.lock.Unlock()
4243
m.syncMan = s
4344
}
4445

46+
// SetIntegrationMan sets integration manager
4547
func (m *Manager) SetIntegrationMan(i IntegrationInterface) {
4648
m.lock.Lock()
4749
defer m.lock.Unlock()
4850
m.integrationMan = i
4951
}
5052

53+
// SetIntegrationConfig sets integration config
5154
func (m *Manager) SetIntegrationConfig(integrations config.Integrations) {
5255
m.lock.Lock()
5356
defer m.lock.Unlock()

gateway/managers/admin/auth_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66
"testing"
77

88
"github.com/spaceuptech/space-cloud/gateway/config"
9-
"github.com/spaceuptech/space-cloud/gateway/model"
109
)
1110

1211
func TestManager_createToken(t *testing.T) {
1312
type fields struct {
14-
quotas model.UsageQuotas
1513
user *config.AdminUser
1614
isProd bool
1715
clusterID string

gateway/managers/admin/integration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ func (m *Manager) GetIntegrationToken(id string) (string, error) {
66
defer m.lock.RUnlock()
77

88
return m.createToken(map[string]interface{}{"id": id, "role": "integration"})
9-
}
9+
}

gateway/managers/admin/operations_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
"github.com/stretchr/testify/mock"
99

1010
"github.com/spaceuptech/space-cloud/gateway/config"
11-
"github.com/spaceuptech/space-cloud/gateway/model"
1211
)
1312

1413
func TestManager_GetClusterID(t *testing.T) {
1514
type fields struct {
16-
quotas model.UsageQuotas
1715
user *config.AdminUser
1816
isProd bool
1917
clusterID string
@@ -45,7 +43,6 @@ func TestManager_GetClusterID(t *testing.T) {
4543

4644
func TestManager_GetCredentials(t *testing.T) {
4745
type fields struct {
48-
quotas model.UsageQuotas
4946
user *config.AdminUser
5047
isProd bool
5148
clusterID string
@@ -104,7 +101,6 @@ func TestManager_IsTokenValid(t *testing.T) {
104101
paramsReturned []interface{}
105102
}
106103
type fields struct {
107-
quotas model.UsageQuotas
108104
user *config.AdminUser
109105
isProd bool
110106
clusterID string

gateway/managers/admin/service.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/spaceuptech/space-cloud/gateway/model"
99
)
1010

11+
// SetServices sets services in admin
1112
func (m *Manager) SetServices(eventType string, services model.ScServices) {
1213
m.lock.Lock()
1314
defer m.lock.Unlock()

gateway/managers/integration/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func (m *Manager) SetConfig(integrations config.Integrations, integrationHooks c
1414
return nil
1515
}
1616

17+
// SetIntegrations sets integtaion config
1718
func (m *Manager) SetIntegrations(integrations config.Integrations) error {
1819
m.lock.Lock()
1920
defer m.lock.Unlock()
@@ -28,6 +29,7 @@ func (m *Manager) SetIntegrations(integrations config.Integrations) error {
2829
return nil
2930
}
3031

32+
// SetIntegrationHooks set integration hooks
3133
func (m *Manager) SetIntegrationHooks(integrationHooks config.IntegrationHooks) {
3234
m.lock.Lock()
3335
defer m.lock.Unlock()

gateway/managers/integration/hook.go

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func (m *Manager) invokeHooks(ctx context.Context, params model.RequestParams) a
9191

9292
case config.IgnoreHookResponse:
9393
// Do nothing
94-
break
9594

9695
case config.HijackHookResponse:
9796
// Check if hook hook has permission to hijack

gateway/managers/integration/integration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/spaceuptech/space-cloud/gateway/config"
77
)
88

9-
// Module is responsible for handling all integration related tasks
9+
// Manager is responsible for handling all integration related tasks
1010
type Manager struct {
1111
lock sync.RWMutex
1212

gateway/managers/syncman/helpers.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func (s *Manager) checkIfDbAliasExists(dbConfigs config.DatabaseConfigs, dbAlias
6767
return nil, false
6868
}
6969

70-
func generatePubSubTopic(nodeID, operation string) string {
71-
return fmt.Sprintf("%s--%s", nodeID, operation)
72-
}
73-
7470
func splitResourceID(ctx context.Context, resourceID string) (clusterID string, projectID string, resource config.Resource, err error) {
7571
arr := strings.Split(resourceID, "--")
7672
// ResourceId format --> clusterId--ProjectId--resourceType--someId-...
@@ -748,6 +744,7 @@ func updateResource(ctx context.Context, eventType string, globalConfig *config.
748744
}
749745
}
750746

747+
// CheckIfLeaderGateway tells if the provided gateway is the current leader gateway or not
751748
func (s *Manager) CheckIfLeaderGateway(nodeID string) (bool, error) {
752749
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
753750
defer cancel()

gateway/managers/syncman/store_local.go

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ type LocalStore struct {
1414
configPath string
1515
globalConfig *config.Config
1616
services model.ScServices
17-
18-
// Callbacks
19-
watchAdminCB func(clusters []*config.Admin)
2017
}
2118

2219
// NewLocalStore creates a new local store

gateway/managers/syncman/syncman.go

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import (
1515
"github.com/spaceuptech/space-cloud/gateway/utils/pubsub"
1616
)
1717

18-
const pubSubOperationRenew = "renew"
19-
const pubSubOperationUpgrade = "upgrade"
20-
2118
// Manager syncs the project config between folders
2219
type Manager struct {
2320
lock sync.RWMutex

gateway/managers/syncman/syncman_auth_test.go

+8-35
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,17 @@ func TestManager_SetUserManagement(t *testing.T) {
124124

125125
func TestManager_GetUserManagement(t *testing.T) {
126126

127-
type mockArgs struct {
128-
method string
129-
args []interface{}
130-
paramsReturned []interface{}
131-
}
132127
type args struct {
133128
ctx context.Context
134129
project string
135130
providerID string
136131
}
137132
tests := []struct {
138-
name string
139-
s *Manager
140-
args args
141-
integrationArgs []mockArgs
142-
want []interface{}
143-
wantErr bool
133+
name string
134+
s *Manager
135+
args args
136+
want []interface{}
137+
wantErr bool
144138
}{
145139
{
146140
name: "unable to get project",
@@ -152,39 +146,18 @@ func TestManager_GetUserManagement(t *testing.T) {
152146
name: "providerID is empty",
153147
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, Auths: map[string]*config.AuthStub{"provider": {ID: "id"}}}}}},
154148
args: args{ctx: context.Background(), project: "1", providerID: "*"},
155-
integrationArgs: []mockArgs{
156-
{
157-
method: "InvokeHook",
158-
args: []interface{}{mock.Anything},
159-
paramsReturned: []interface{}{mockHookResponse{}},
160-
},
161-
},
162149
want: []interface{}{&config.AuthStub{ID: "id"}},
163150
},
164151
{
165-
name: "providerID is not present in config",
166-
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, Auths: map[string]*config.AuthStub{"provider": {ID: "id"}}}}}},
167-
args: args{ctx: context.Background(), project: "1", providerID: "notProvider"},
168-
integrationArgs: []mockArgs{
169-
{
170-
method: "InvokeHook",
171-
args: []interface{}{mock.Anything},
172-
paramsReturned: []interface{}{mockHookResponse{}},
173-
},
174-
},
152+
name: "providerID is not present in config",
153+
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, Auths: map[string]*config.AuthStub{"provider": {ID: "id"}}}}}},
154+
args: args{ctx: context.Background(), project: "1", providerID: "notProvider"},
175155
wantErr: true,
176156
},
177157
{
178158
name: "providerID is present in config",
179159
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, Auths: map[string]*config.AuthStub{config.GenerateResourceID("chicago", "1", config.ResourceAuthProvider, "provider"): {ID: "provider"}}}}}},
180160
args: args{ctx: context.Background(), project: "1", providerID: "provider"},
181-
integrationArgs: []mockArgs{
182-
{
183-
method: "InvokeHook",
184-
args: []interface{}{mock.Anything},
185-
paramsReturned: []interface{}{mockHookResponse{}},
186-
},
187-
},
188161
want: []interface{}{&config.AuthStub{ID: "provider"}},
189162
},
190163
}

gateway/managers/syncman/syncman_integration.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/spaceuptech/space-cloud/gateway/model"
1616
)
1717

18+
// EnableIntegration enables integration
1819
func (s *Manager) EnableIntegration(ctx context.Context, integrationConfig *config.IntegrationConfig, params model.RequestParams) (int, error) {
1920
// Check if the request has been hijacked
2021
hookResponse := s.integrationMan.InvokeHook(ctx, params)
@@ -77,7 +78,9 @@ func (s *Manager) EnableIntegration(ctx context.Context, integrationConfig *conf
7778
// if err != nil {
7879
// return http.StatusBadRequest, helpers.Logger.LogError(helpers.GetRequestID(ctx), "Unable to parse integration license", err, nil)
7980
// }
80-
license := make(map[string]interface{}, 0)
81+
// NOTE: This is just to resolve linting errors, as integration is depreciated
82+
// If integration is brough back, then change these lines
83+
license := make(map[string]interface{})
8184
integrationConfig.Deployments = license["deployments"].([]interface{})
8285
for _, service := range integrationConfig.Deployments {
8386
obj := service.(map[string]interface{})
@@ -322,7 +325,7 @@ func (s *Manager) RemoveIntegrationHook(ctx context.Context, integrationID, hook
322325
return http.StatusOK, nil
323326
}
324327

325-
// GetIntegrationHook removes an integration hook
328+
// GetIntegrationHooks gets a integration hook
326329
func (s *Manager) GetIntegrationHooks(ctx context.Context, integrationID, hookID string, params model.RequestParams) (int, []interface{}, error) {
327330
// Check if the request has been hijacked
328331
hookResponse := s.integrationMan.InvokeHook(ctx, params)

gateway/model/cache.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type CachePurgeRequest struct {
1111
Resource config.Resource `json:"resource,omitempty"`
1212
DbAlias string `json:"dbAlias,omitempty"`
13-
ServiceId string `json:"serviceId,omitempty"`
13+
ServiceID string `json:"serviceId,omitempty"`
1414
ID string `json:"id,omitempty"`
1515
}
1616

@@ -20,6 +20,7 @@ type CacheIngressRoute struct {
2020
Headers http.Header `json:"headers"`
2121
}
2222

23+
// CacheDatabaseResult is used to store cached database result
2324
type CacheDatabaseResult struct {
2425
Result interface{} `json:"result"`
2526
MetricCount int64 `json:"metricCount"`

gateway/model/quotas.go

+8
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,49 @@ type UsageQuotasResult struct {
1313
Error string `json:"error"`
1414
}
1515

16+
// UpgradeResponse is the response of upgrade request
1617
type UpgradeResponse struct {
1718
Error string `json:"error"`
1819
License string `json:"license"`
1920
}
2021

22+
// GraphqlFetchLicenseResponse is the response fetch license request
2123
type GraphqlFetchLicenseResponse struct {
2224
Result *UpgradeResponse `json:"result"`
2325
Error string `json:"error"`
2426
Message string `json:"message"`
2527
Status int `json:"status"`
2628
}
2729

30+
// GraphqlFetchPublicKeyResponse is the response fetch public key request
2831
type GraphqlFetchPublicKeyResponse struct {
2932
Result string `json:"result"`
3033
Error string `json:"error"`
3134
Message string `json:"message"`
3235
Status int `json:"status"`
3336
}
3437

38+
// License stores license info
3539
type License struct {
3640
LicenseKey string `json:"licenseKey" mapstructure:"licenseKey" structs:"licenseKey"`
3741
LicenseRenewal string `json:"licenseRenewal" mapstructure:"licenseRenewal" structs:"licenseRenewal"`
3842
SessionID string `json:"sessionId" mapstructure:"sessionId" structs:"sessionId"`
3943
Plan string `json:"plan" mapstructure:"plan" structs:"plan"`
4044
Meta *LicenseTokenMeta `json:"meta" mapstructure:"meta" structs:"meta"`
4145
}
46+
47+
// LicenseTokenMeta stores license token meta info
4248
type LicenseTokenMeta struct {
4349
ProductMeta *UsageQuotas `json:"productMeta" mapstructure:"productMeta" structs:"productMeta"`
4450
LicenseKeyMeta *LicenseKeyMeta `json:"licenseKeyMeta" mapstructure:"licenseKeyMeta" structs:"licenseKeyMeta"`
4551
}
4652

53+
// LicenseKeyMeta stores license key meta
4754
type LicenseKeyMeta struct {
4855
ClusterName string `json:"clusterName" mapstructure:"clusterName" structs:"clusterName"`
4956
}
5057

58+
// RenewLicense is the body for renew license request
5159
type RenewLicense struct {
5260
ClusterName string `json:"clusterName"`
5361
LicenseValue string `json:"licenseValue"`

gateway/model/request.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type BatchSpecApplyRequest struct {
3030
Specs []*SpecObject `json:"specs" yaml:"specs"`
3131
}
3232

33+
// LicenseUpgradeRequest is the body of license upgrade request
3334
type LicenseUpgradeRequest struct {
3435
LicenseKey string `json:"licenseKey" mapstructure:"licenseKey"`
3536
LicenseValue string `json:"licenseValue" mapstructure:"licenseValue"`

gateway/model/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/spaceuptech/space-cloud/gateway/config"
88
)
99

10+
// SyncManAdminInterface is an interface consisting of functions of synman module used by auth admin module
1011
type SyncManAdminInterface interface {
1112
CheckIfLeaderGateway(nodeID string) (bool, error)
1213
}
@@ -168,10 +169,12 @@ type ReturnWhereStub struct {
168169
PrefixColName bool
169170
}
170171

172+
// Service stores id of the service
171173
type Service struct {
172174
ID string
173175
}
174176

177+
// ScServices stores array of gateway services
175178
type ScServices []*Service
176179

177180
func (a ScServices) Len() int { return len(a) }

gateway/modules/auth/auth.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (m *Module) GetSCAccessToken(ctx context.Context) (string, error) {
5858
})
5959
}
6060

61+
// IsSCAccessToken checks if its an SC access token
6162
func (m *Module) IsSCAccessToken(ctx context.Context, token string) error {
6263
claims, err := m.ParseToken(ctx, token)
6364
if err != nil {

gateway/modules/crud/setters.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (m *Module) SetAdminManager(a *admin.Manager) {
182182
m.admin = a
183183
}
184184

185-
// SetAdminManager sets the integration manager
185+
// SetIntegrationManager sets the integration manager
186186
func (m *Module) SetIntegrationManager(i integrationManagerInterface) {
187187
m.integrationMan = i
188188
}

gateway/modules/eventing/operations.go

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (m *Module) SetRealtimeTriggers(eventingRules []*config.EventingTrigger) {
130130
}
131131
}
132132

133+
// SetInternalTriggersFromDbRules set internal triggers from db rules
133134
func (m *Module) SetInternalTriggersFromDbRules(dbRules config.DatabaseRules) {
134135
m.lock.Lock()
135136
defer m.lock.Unlock()

0 commit comments

Comments
 (0)