Skip to content

Commit a693a9c

Browse files
authored
Merge pull request #1273 from spaceuptech/v0.19.2
V0.19.2
2 parents 8aeddb3 + 4a552ae commit a693a9c

File tree

279 files changed

+3656
-3856
lines changed

Some content is hidden

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

279 files changed

+3656
-3856
lines changed

gateway/Dockerfile

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

44
# Take the current space cloud version as a argument
5-
ARG SC_VERSION=0.19.1
5+
ARG SC_VERSION=0.19.2
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.10
19-
ARG SC_VERSION=0.19.1
19+
ARG SC_VERSION=0.19.2
2020

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

gateway/config/generate.go

-134
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
package config
22

3-
import (
4-
"fmt"
5-
"html/template"
6-
"os"
7-
"strings"
8-
9-
"gopkg.in/AlecAivazis/survey.v1"
10-
11-
"github.com/spaceuptech/space-cloud/gateway/utils"
12-
)
13-
14-
type input struct {
15-
Conn string
16-
PrimaryDB string
17-
ID string
18-
Name string
19-
AdminName string
20-
AdminPass string
21-
AdminRole string
22-
AdminSecret string
23-
HomeDir string
24-
BuildVersion string
25-
}
26-
273
// GenerateEmptyConfig creates an empty config file
284
func GenerateEmptyConfig() *Config {
295

@@ -38,113 +14,3 @@ func GenerateEmptyConfig() *Config {
3814
Projects: []*Project{},
3915
}
4016
}
41-
42-
// GenerateConfig started the interactive cli to generate config file
43-
func GenerateConfig(configFilePath string) error {
44-
fmt.Println()
45-
fmt.Println("This utility walks you through creating a config.yaml file for your space-cloud project.")
46-
fmt.Println("It only covers the most essential configurations and suggests sensible defaults.")
47-
fmt.Println()
48-
fmt.Println("Press ^C any time to quit.")
49-
50-
i := new(input)
51-
52-
// Ask the project id
53-
workingDir, _ := os.Getwd()
54-
array := strings.Split(workingDir, string(os.PathSeparator))
55-
dir := array[len(array)-1]
56-
err := survey.AskOne(&survey.Input{Message: "project name:", Default: formatProjectID(dir)}, &i.Name, survey.Required)
57-
if err != nil {
58-
return err
59-
}
60-
i.ID = formatProjectID(i.Name)
61-
62-
// Ask the primary db
63-
err = survey.AskOne(&survey.Select{
64-
Message: "primary database:",
65-
Options: []string{"mongo", "mysql", "postgres"},
66-
Default: "mongo",
67-
}, &i.PrimaryDB, survey.Required)
68-
if err != nil {
69-
return err
70-
}
71-
72-
// Ask for the connection string
73-
err = survey.AskOne(&survey.Input{Message: "connection string (" + i.PrimaryDB + ")", Default: getConnectionString(i.PrimaryDB)}, &i.Conn, survey.Required)
74-
if err != nil {
75-
return err
76-
}
77-
78-
// Ask for the admin username
79-
err = survey.AskOne(&survey.Input{Message: "Mission Control (UserName)", Default: "admin"}, &i.AdminName, survey.Required)
80-
if err != nil {
81-
return err
82-
}
83-
84-
// Ask for the admin password
85-
err = survey.AskOne(&survey.Input{Message: "Mission Control (Password)", Default: "123"}, &i.AdminPass, survey.Required)
86-
if err != nil {
87-
return err
88-
}
89-
90-
// Ask for the admin role
91-
err = survey.AskOne(&survey.Input{Message: "Mission Control (Role)", Default: "captain-cloud"}, &i.AdminRole, survey.Required)
92-
if err != nil {
93-
return err
94-
}
95-
96-
// Ask for the admin secret
97-
err = survey.AskOne(&survey.Input{Message: "Mission Control (JWT Secret)", Default: "some-secret"}, &i.AdminSecret, survey.Required)
98-
if err != nil {
99-
return err
100-
}
101-
102-
i.HomeDir = utils.UserHomeDir()
103-
i.BuildVersion = utils.BuildVersion
104-
105-
if configFilePath == "none" {
106-
configFilePath = workingDir + string(os.PathSeparator) + i.ID + ".yaml"
107-
}
108-
109-
return writeConfig(i, configFilePath)
110-
}
111-
112-
func writeConfig(i *input, configFilePath string) error {
113-
f, err := os.Create(configFilePath)
114-
if err != nil {
115-
return err
116-
}
117-
defer utils.CloseTheCloser(f)
118-
119-
tmplString := templateString
120-
121-
tmpl, err := template.New("config").Parse(tmplString)
122-
if err != nil {
123-
return err
124-
}
125-
126-
err = tmpl.Execute(f, i)
127-
if err != nil {
128-
return err
129-
}
130-
131-
return f.Sync()
132-
}
133-
134-
func formatProjectID(id string) string {
135-
return strings.Join(strings.Split(strings.ToLower(id), " "), "-")
136-
}
137-
138-
func getConnectionString(db string) string {
139-
140-
switch db {
141-
case string(utils.Mongo):
142-
return "mongodb://localhost:27017"
143-
case string(utils.MySQL):
144-
return "user:my-secret-pwd@/project"
145-
case string(utils.Postgres):
146-
return "postgres://postgres:mysecretpassword@localhost/postgres?sslmode=disable"
147-
default:
148-
return "localhost"
149-
}
150-
}

gateway/config/routing.go

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

33
import (
4+
"context"
45
"fmt"
56
"math/rand"
67
"strings"
8+
9+
"github.com/spaceuptech/helpers"
710
)
811

912
// GlobalRoutesConfig describes the project level config for ingress routing
@@ -57,7 +60,7 @@ type Route struct {
5760
}
5861

5962
// SelectTarget returns a target based on the weights assigned
60-
func (r *Route) SelectTarget(weight int32) (RouteTarget, error) {
63+
func (r *Route) SelectTarget(ctx context.Context, weight int32) (RouteTarget, error) {
6164

6265
// Generate a random float in the range 0 to 100 if provided weight in lesser than zero
6366
if weight < 0 {
@@ -75,7 +78,7 @@ func (r *Route) SelectTarget(weight int32) (RouteTarget, error) {
7578
}
7679

7780
// Return error if no targets match
78-
return RouteTarget{}, fmt.Errorf("no target found for route (%s) - make sure you have defined atleast one target with proper weights", r.Source.URL)
81+
return RouteTarget{}, helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("No target found for route (%s) - make sure you have defined atleast one target with proper weights", r.Source.URL), nil, nil)
7982
}
8083

8184
// RouteSource is the source of routing

gateway/config/routing_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"context"
45
"reflect"
56
"testing"
67
)
@@ -63,7 +64,7 @@ func TestRoute_SelectTarget(t *testing.T) {
6364
Source: tt.fields.Source,
6465
Targets: tt.fields.Targets,
6566
}
66-
got, err := r.SelectTarget(tt.args.weight)
67+
got, err := r.SelectTarget(context.Background(), tt.args.weight)
6768
if (err != nil) != tt.wantErr {
6869
t.Errorf("SelectTarget() error = %v, wantErr %v", err, tt.wantErr)
6970
return

gateway/config/template.go

-76
This file was deleted.

gateway/go.mod

+7-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/google/go-cmp v0.5.0
2525
github.com/googleapis/gnostic v0.3.1 // indirect
2626
github.com/gorilla/mux v1.7.3
27-
github.com/gorilla/websocket v1.4.1
27+
github.com/gorilla/websocket v1.4.2
2828
github.com/graph-gophers/dataloader v5.0.0+incompatible
2929
github.com/graphql-go/graphql v0.7.8
3030
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
@@ -37,19 +37,18 @@ require (
3737
github.com/huandu/xstrings v1.3.2 // indirect
3838
github.com/jmoiron/sqlx v1.2.0
3939
github.com/jonboulle/clockwork v0.1.0 // indirect
40-
github.com/kr/pty v1.1.4 // indirect
4140
github.com/lib/pq v1.2.0
42-
github.com/mattn/go-colorable v0.1.2 // indirect
4341
github.com/mattn/go-sqlite3 v1.11.0 // indirect
4442
github.com/mholt/certmagic v0.9.1
4543
github.com/mitchellh/copystructure v1.0.0 // indirect
46-
github.com/mitchellh/mapstructure v1.1.2
44+
github.com/mitchellh/mapstructure v1.3.3
4745
github.com/rs/cors v1.7.0
4846
github.com/satori/go.uuid v1.2.0
49-
github.com/segmentio/ksuid v1.0.2
50-
github.com/sirupsen/logrus v1.4.2
47+
github.com/segmentio/ksuid v1.0.3
48+
github.com/sirupsen/logrus v1.6.0 // indirect
5149
github.com/soheilhy/cmux v0.1.4 // indirect
52-
github.com/spaceuptech/space-api-go v0.17.3
50+
github.com/spaceuptech/helpers v0.1.1
51+
github.com/spaceuptech/space-api-go v0.18.1
5352
github.com/stretchr/objx v0.2.0 // indirect
5453
github.com/stretchr/testify v1.5.1
5554
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51 // indirect
@@ -61,11 +60,10 @@ require (
6160
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
6261
go.etcd.io/bbolt v1.3.3
6362
go.mongodb.org/mongo-driver v1.1.1
64-
go.uber.org/zap v1.15.0 // indirect
6563
golang.org/x/crypto v0.0.0-20200219234226-1ad67e1f0ef4
6664
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0
65+
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
6766
google.golang.org/api v0.18.0
68-
gopkg.in/AlecAivazis/survey.v1 v1.8.5
6967
gopkg.in/yaml.v2 v2.2.7 // indirect
7068
k8s.io/api v0.17.2
7169
k8s.io/apimachinery v0.17.2

0 commit comments

Comments
 (0)