Skip to content

Commit 93137e0

Browse files
authored
Merge pull request #1552 from spaceuptech/v0.21.4
V0.21.4
2 parents 814b39f + fbdb0ae commit 93137e0

File tree

171 files changed

+6307
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+6307
-800
lines changed

.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
*.out
1414

1515
**/node_modules/**
16-
css
16+
mission-control/public/**
17+
mission-control/src/**
18+
mission-control/node_modules/**
19+
1720
.sass-cache
1821

1922
# Ignore the binaries

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test
1212
*.dylib
1313
*.db
1414
# Test binary, build with `go test -c`
15-
*.test
15+
*.test
1616

1717
# sh file for bash completion
1818
*.sh
@@ -56,10 +56,8 @@ gateway/scripts
5656
metric-proxy/scripts
5757
docker-build.sh
5858

59-
59+
scripts/*
6060
#IDEs
61-
.idea
62-
.vscode
6361

6462
yarn.lock
6563

gateway/.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.zip
2+
gateway

gateway/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:1.15.3-alpine3.12
22
WORKDIR /build
33

44
# Take the current space cloud version as a argument
5-
ARG SC_VERSION=0.21.3
5+
ARG SC_VERSION=0.21.4
66

77
# Copy all the source files
88
COPY . .
@@ -16,7 +16,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -a -ldflags '-s -w -extldflags "-static"'
1616
RUN echo $SC_VERSION && wget https://storage.googleapis.com/space-cloud/mission-control/mission-control-v$SC_VERSION.zip && unzip mission-control-v$SC_VERSION.zip
1717

1818
FROM alpine:3.12
19-
ARG SC_VERSION=0.21.3
19+
ARG SC_VERSION=0.21.4
2020

2121
RUN apk --no-cache add ca-certificates
2222

gateway/config/config.go

+35-19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Config struct {
1111
ClusterConfig *ClusterConfig `json:"clusterConfig" yaml:"clusterConfig" mapstructure:"clusterConfig"`
1212
Integrations Integrations `json:"integrations" yaml:"integrations" mapstructure:"integrations"`
1313
IntegrationHooks IntegrationHooks `json:"integrationsHooks" yaml:"integrationsHooks" mapstructure:"integrationsHooks"`
14+
CacheConfig *CacheConfig `json:"cacheConfig" yaml:"cacheConfig" mapstructure:"cacheConfig"`
1415
}
1516

1617
// ClusterConfig holds the cluster level configuration
@@ -119,10 +120,11 @@ type DatabaseSchema struct {
119120

120121
// DatabaseRule stores information of db rule
121122
type DatabaseRule struct {
122-
Table string `json:"col,omitempty" yaml:"col" mapstructure:"col"`
123-
DbAlias string `json:"dbAlias,omitempty" yaml:"dbAlias" mapstructure:"dbAlias"`
124-
IsRealTimeEnabled bool `json:"isRealtimeEnabled,omitempty" yaml:"isRealtimeEnabled" mapstructure:"isRealtimeEnabled"`
125-
Rules map[string]*Rule `json:"rules,omitempty" yaml:"rules" mapstructure:"rules"`
123+
Table string `json:"col,omitempty" yaml:"col" mapstructure:"col"`
124+
DbAlias string `json:"dbAlias,omitempty" yaml:"dbAlias" mapstructure:"dbAlias"`
125+
IsRealTimeEnabled bool `json:"isRealtimeEnabled,omitempty" yaml:"isRealtimeEnabled" mapstructure:"isRealtimeEnabled"`
126+
EnableCacheInvalidation bool `json:"enableCacheInvalidation,omitempty" yaml:"enableCacheInvalidation" mapstructure:"enableCacheInvalidation"`
127+
Rules map[string]*Rule `json:"rules,omitempty" yaml:"rules" mapstructure:"rules"`
126128
}
127129

128130
// EventingConfig stores information of eventing config
@@ -150,6 +152,15 @@ type FileStoreConfig struct {
150152
ForcePathStyle *bool `json:"forcePathStyle,omitempty" yaml:"forcePathStyle,omitempty" mapstructure:"forcePathStyle"`
151153
}
152154

155+
// CacheConfig describes the config of the caching module
156+
type CacheConfig struct {
157+
Enabled bool `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
158+
Conn string `json:"conn" yaml:"conn" mapstructure:"conn"`
159+
160+
// Represents Time To Live in seconds, default value is 5 minutes (5 * 60 seconds) if not provided
161+
DefaultTTL int `json:"defaultTTL" yaml:"defaultTTL" mapstructure:"defaultTTL"`
162+
}
163+
153164
// Secret describes the a secret object
154165
type Secret struct {
155166
IsPrimary bool `json:"isPrimary" yaml:"isPrimary" mapstructure:"isPrimary"` // used by the frontend & backend to generate token out of multiple secrets
@@ -191,9 +202,6 @@ const (
191202
// Admin holds the admin config
192203
type Admin struct {
193204
ClusterConfig *ClusterConfig `json:"clusterConfig" yaml:"clusterConfig" mapstructure:"clusterConfig"`
194-
LicenseKey string `json:"licenseKey" yaml:"licenseKey" mapstructure:"licenseKey"`
195-
LicenseValue string `json:"licenseValue" yaml:"licenseValue" mapstructure:"licenseValue"`
196-
License string `json:"license" yaml:"license" mapstructure:"license"`
197205
Integrations Integrations `json:"integrations" yaml:"integrations" mapstructure:"integrations"`
198206
}
199207

@@ -273,6 +281,7 @@ type Rule struct {
273281
Template TemplatingEngine `json:"template,omitempty" yaml:"template,omitempty" mapstructure:"template"`
274282
ReqTmpl string `json:"requestTemplate,omitempty" yaml:"requestTemplate,omitempty" mapstructure:"requestTemplate"`
275283
OpFormat string `json:"outputFormat,omitempty" yaml:"outputFormat,omitempty" mapstructure:"outputFormat"`
284+
Cache *ReadCacheOptions `json:"cache,omitempty" yaml:"cache,omitempty" mapstructure:"cache"`
276285
}
277286

278287
// Auths holds the mapping of the sign in method
@@ -309,18 +318,19 @@ type Endpoint struct {
309318
// depending upon the payload format, the graphQL request that
310319
// gets converted to http request will use that format as it's payload
311320
// currently supported formats are application/json,multipart/form-data
312-
ReqPayloadFormat string `json:"requestPayloadFormat" yaml:"requestPayloadFormat" mapstructure:"requestPayloadFormat"`
313-
ReqTmpl string `json:"requestTemplate" yaml:"requestTemplate" mapstructure:"requestTemplate"`
314-
GraphTmpl string `json:"graphTemplate" yaml:"graphTemplate" mapstructure:"graphTemplate"`
315-
ResTmpl string `json:"responseTemplate" yaml:"responseTemplate" mapstructure:"responseTemplate"`
316-
OpFormat string `json:"outputFormat,omitempty" yaml:"outputFormat,omitempty" mapstructure:"outputFormat"`
317-
Token string `json:"token,omitempty" yaml:"token,omitempty" mapstructure:"token"`
318-
Claims string `json:"claims,omitempty" yaml:"claims,omitempty" mapstructure:"claims"`
319-
Method string `json:"method" yaml:"method" mapstructure:"method"`
320-
Path string `json:"path" yaml:"path" mapstructure:"path"`
321-
Rule *Rule `json:"rule,omitempty" yaml:"rule,omitempty" mapstructure:"rule"`
322-
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty" mapstructure:"headers"`
323-
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty" mapstructure:"timeout"` // Timeout is in seconds
321+
ReqPayloadFormat string `json:"requestPayloadFormat" yaml:"requestPayloadFormat" mapstructure:"requestPayloadFormat"`
322+
ReqTmpl string `json:"requestTemplate" yaml:"requestTemplate" mapstructure:"requestTemplate"`
323+
GraphTmpl string `json:"graphTemplate" yaml:"graphTemplate" mapstructure:"graphTemplate"`
324+
ResTmpl string `json:"responseTemplate" yaml:"responseTemplate" mapstructure:"responseTemplate"`
325+
OpFormat string `json:"outputFormat,omitempty" yaml:"outputFormat,omitempty" mapstructure:"outputFormat"`
326+
Token string `json:"token,omitempty" yaml:"token,omitempty" mapstructure:"token"`
327+
Claims string `json:"claims,omitempty" yaml:"claims,omitempty" mapstructure:"claims"`
328+
Method string `json:"method" yaml:"method" mapstructure:"method"`
329+
Path string `json:"path" yaml:"path" mapstructure:"path"`
330+
Rule *Rule `json:"rule,omitempty" yaml:"rule,omitempty" mapstructure:"rule"`
331+
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty" mapstructure:"headers"`
332+
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty" mapstructure:"timeout"` // Timeout is in seconds
333+
CacheOptions []string `json:"cacheOptions" yaml:"cacheOptions" mapstructure:"cacheOptions"`
324334
}
325335

326336
// EndpointKind describes the type of endpoint. Default value - internal
@@ -448,3 +458,9 @@ type LetsEncrypt struct {
448458
ID string `json:"id,omitempty" yaml:"id,omitempty" mapstructure:"id"`
449459
WhitelistedDomains []string `json:"domains" yaml:"domains" mapstructure:"domains"`
450460
}
461+
462+
// ReadCacheOptions describes the cache options in requests
463+
type ReadCacheOptions struct {
464+
TTL int64 `json:"ttl" yaml:"ttl" mapstructure:"ttl"` // here ttl is represented in seconds
465+
InstantInvalidate bool `json:"instantInvalidate" yaml:"instantInvalidate" mapstructure:"instantInvalidate"`
466+
}

gateway/config/generate.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func GenerateEmptyConfig() *Config {
88
ClusterConfig: new(ClusterConfig),
99
Integrations: make(Integrations),
1010
IntegrationHooks: make(IntegrationHooks),
11+
CacheConfig: new(CacheConfig),
1112
}
1213
}
1314

gateway/config/integration.go

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type IntegrationConfig struct {
3030
AppURL string `json:"appUrl" yaml:"appUrl" mapstructure:"appUrl"`
3131
CompatibleVersion string `json:"compatibleVersion" yaml:"compatibleVersion" mapstructure:"compatibleVersion"`
3232
CompatibleVersionNo int `json:"compatibleVersionNo" yaml:"compatibleVersionNo" mapstructure:"compatibleVersionNo"`
33+
Details string `json:"details" yaml:"details" mapstructure:"details"`
34+
Description string `json:"description" yaml:"description" mapstructure:"description"`
3335
}
3436

3537
// IntegrationHook describes the config for a integration hook
@@ -66,6 +68,9 @@ type IntegrationAuthResponse interface {
6668
// an integration is trying to configure a resource which it does not have access to.
6769
Error() error
6870

71+
// Status returns the status code returned by the integration
72+
Status() int
73+
6974
// Result returns the value returned by the the hook. It will always be an []interface{} or map[string]interface{}.
7075
// The receiver must decode it into the appropriate struct if necessary.
7176
Result() interface{}

gateway/config/resource.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var ResourceFetchingOrder = []Resource{
2626
ResourceCluster,
2727
ResourceIntegration,
2828
ResourceIntegrationHook,
29+
ResourceCacheConfig,
2930
}
3031

3132
// Resource is a resource type
@@ -79,6 +80,9 @@ const (
7980
// ResourceCluster is a resource
8081
ResourceCluster Resource = "cluster"
8182

83+
// ResourceCacheConfig is a resource
84+
ResourceCacheConfig Resource = "cache-config"
85+
8286
// ResourceDeployService is a resource
8387
// ResourceDeployService Resource = "service"
8488
// ResourceDeployServiceRoute is a resource

gateway/config/routing.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ func (a Routes) Less(i, j int) bool {
4444

4545
// Route describes the parameters of a single route
4646
type Route struct {
47-
ID string `json:"id" yaml:"id" mapstructure:"id"`
48-
Project string `json:"project" yaml:"project" mapstructure:"project"`
49-
Source RouteSource `json:"source" yaml:"source" mapstructure:"source"`
50-
Targets []RouteTarget `json:"targets" yaml:"targets" mapstructure:"targets"`
51-
Rule *Rule `json:"rule" yaml:"rule" mapstructure:"rule"`
52-
Modify struct {
47+
ID string `json:"id" yaml:"id" mapstructure:"id"`
48+
Project string `json:"project" yaml:"project" mapstructure:"project"`
49+
Source RouteSource `json:"source" yaml:"source" mapstructure:"source"`
50+
Targets []RouteTarget `json:"targets" yaml:"targets" mapstructure:"targets"`
51+
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"`
54+
Modify struct {
5355
Tmpl TemplatingEngine `json:"template,omitempty" yaml:"template,omitempty" mapstructure:"template"`
5456
ReqTmpl string `json:"requestTemplate" yaml:"requestTemplate" mapstructure:"requestTemplate"`
5557
ResTmpl string `json:"responseTemplate" yaml:"responseTemplate" mapstructure:"responseTemplate"`

gateway/config/store.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package config
22

33
import (
4+
"context"
45
"encoding/json"
5-
"errors"
6+
"fmt"
67
"io/ioutil"
78
"strings"
89

910
"github.com/ghodss/yaml"
11+
"github.com/spaceuptech/helpers"
1012
)
1113

1214
// StoreConfigToFile stores the config file to disk
@@ -19,7 +21,7 @@ func StoreConfigToFile(conf *Config, path string) error {
1921
} else if strings.HasSuffix(path, ".json") {
2022
data, err = json.Marshal(conf)
2123
} else {
22-
return errors.New("Invalid config file type")
24+
return helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), fmt.Sprintf("Invalid config file type (%s) provided", path), nil, nil)
2325
}
2426

2527
// Check if error occured while marshaling

gateway/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ require (
5656

5757
)
5858

59+
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
60+
5961
go 1.15

gateway/main.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var essentialFlags = []cli.Flag{
117117
// Flags for the metrics module
118118
cli.BoolFlag{
119119
Name: "disable-metrics",
120-
Usage: "Disable anonymous metric collection",
120+
Usage: "Delete anonymous metric collection",
121121
EnvVar: "DISABLE_METRICS",
122122
},
123123

@@ -132,7 +132,7 @@ var essentialFlags = []cli.Flag{
132132
func main() {
133133
app := cli.NewApp()
134134
app.Version = utils.BuildVersion
135-
app.Name = "space-cloud"
135+
app.Name = "space-cloud-ee"
136136
app.Usage = "core binary to run space cloud"
137137

138138
app.Commands = []cli.Command{
@@ -165,7 +165,6 @@ func actionRun(c *cli.Context) error {
165165
// Load cli flags
166166
nodeID := c.String("id")
167167
isDev := c.Bool("dev")
168-
profiler := c.Bool("profiler")
169168
logLevel := c.String("log-level")
170169
logFormat := c.String("log-format")
171170

@@ -199,7 +198,7 @@ func actionRun(c *cli.Context) error {
199198

200199
// Generate a new id if not provided
201200
if nodeID == "none" {
202-
nodeID = "auto-" + ksuid.New().String()
201+
nodeID = fmt.Sprintf("auto-%s", ksuid.New().String())
203202
}
204203

205204
helpers.Logger.LogInfo("start", fmt.Sprintf("Starting node with id - %s", nodeID), nil)
@@ -235,7 +234,7 @@ func actionRun(c *cli.Context) error {
235234
}
236235
}
237236

238-
return s.Start(profiler, staticPath, port, strings.Split(c.String("restrict-hosts"), ","))
237+
return s.Start(false, staticPath, port, strings.Split(c.String("restrict-hosts"), ","))
239238
}
240239

241240
func actionHealthCheck(c *cli.Context) error {

gateway/managers/admin/admin.go

+55-10
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,81 @@
11
package admin
22

33
import (
4+
"context"
45
"sync"
6+
"time"
57

68
"github.com/spaceuptech/space-cloud/gateway/config"
79
"github.com/spaceuptech/space-cloud/gateway/model"
810
)
911

1012
// Manager manages all admin transactions
1113
type Manager struct {
12-
lock sync.RWMutex
13-
quotas model.UsageQuotas
14-
user *config.AdminUser
15-
isProd bool
14+
lock sync.RWMutex
15+
user *config.AdminUser
16+
integrations config.Integrations
17+
18+
services model.ScServices
19+
isProd bool
20+
21+
syncMan model.SyncManAdminInterface
22+
integrationMan IntegrationInterface
1623

1724
nodeID, clusterID string
1825
}
1926

2027
// New creates a new admin manager instance
2128
func New(nodeID, clusterID string, isDev bool, adminUserInfo *config.AdminUser) *Manager {
2229
m := new(Manager)
23-
m.user = adminUserInfo
24-
m.quotas = model.UsageQuotas{MaxDatabases: 1, MaxProjects: 1}
2530
m.nodeID = nodeID
31+
m.isProd = !isDev // set inverted
2632
m.clusterID = clusterID
27-
m.isProd = !isDev
33+
34+
m.integrations = make(config.Integrations)
35+
m.user = adminUserInfo
2836
return m
2937
}
3038

31-
// LoadEnv gets the env
32-
func (m *Manager) LoadEnv() (bool, string, model.UsageQuotas, string, string, string, string, string, string, string) {
39+
// SetSyncMan sets syncman manager
40+
func (m *Manager) SetSyncMan(s model.SyncManAdminInterface) {
41+
m.lock.Lock()
42+
defer m.lock.Unlock()
43+
m.syncMan = s
44+
}
45+
46+
// SetIntegrationMan sets integration manager
47+
func (m *Manager) SetIntegrationMan(i IntegrationInterface) {
3348
m.lock.Lock()
3449
defer m.lock.Unlock()
35-
return m.isProd, "space-cloud-open", m.quotas, "/mission-control/login", "", "", "", "", "", "online"
50+
m.integrationMan = i
51+
}
52+
53+
// SetIntegrationConfig sets integration config
54+
func (m *Manager) SetIntegrationConfig(integrations config.Integrations) {
55+
m.lock.Lock()
56+
defer m.lock.Unlock()
57+
m.integrations = integrations
58+
}
59+
60+
// LoadEnv gets the env
61+
func (m *Manager) LoadEnv() (bool, string, error) {
62+
m.lock.RLock()
63+
defer m.lock.RUnlock()
64+
65+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
66+
defer cancel()
67+
68+
loginURL := "/mission-control/login"
69+
70+
// Invoke integration hooks
71+
hookResponse := m.integrationMan.InvokeHook(ctx, model.RequestParams{
72+
Resource: "load-env",
73+
Op: "read",
74+
})
75+
if hookResponse.CheckResponse() {
76+
if err := hookResponse.Error(); err == nil {
77+
loginURL = hookResponse.Result().(map[string]interface{})["loginUrl"].(string)
78+
}
79+
}
80+
return m.isProd, loginURL, nil
3681
}

gateway/managers/admin/admin_test.go

-1
This file was deleted.

0 commit comments

Comments
 (0)