Skip to content

Commit 41dccf6

Browse files
authored
Merge pull request #1332 from spaceuptech/v0.19.4
v0.19.4
2 parents 1fe2f5a + 7ef90d9 commit 41dccf6

36 files changed

+6824
-1202
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.3
5+
ARG SC_VERSION=0.19.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.10
19-
ARG SC_VERSION=0.19.3
19+
ARG SC_VERSION=0.19.4
2020

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

gateway/config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type Secret struct {
4040
JwkURL string `json:"jwkUrl" yaml:"jwkUrl"`
4141
JwkKey interface{} `json:"-" yaml:"-"`
4242

43+
Audience []string `json:"aud" yaml:"aud"`
44+
Issuer []string `json:"iss" yaml:"iss"`
45+
4346
// Used for HMAC256 secret
4447
Secret string `json:"secret" yaml:"secret"`
4548

gateway/integration_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go build .
88
sudo kill -9 `sudo lsof -t -i:4122`
99

1010
# run the gateway in background
11-
./gateway run --dev &> /dev/null &
11+
./gateway run --dev --log-format text &> /dev/null &
1212
sleep 10
1313
#sc_process_num=$!
1414

gateway/model/schema_type.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type (
3131
LinkedTable *TableProperties `json:"linkedTable"`
3232
JointTable *TableProperties `json:"jointTable"`
3333
Default interface{} `json:"default"`
34+
TypeIDSize int `json:"size"`
3435
}
3536

3637
// TableProperties are properties of the table
@@ -59,8 +60,8 @@ const (
5960
TypeID string = "ID"
6061
// TypeJSON is variable used for Variable of type Jsonb
6162
TypeJSON string = "JSON"
62-
// SQLTypeIDSize is variable used for specifing si ze of sql type ID
63-
SQLTypeIDSize string = "50"
63+
// SQLTypeIDSize is variable used for specifying size of sql type ID
64+
SQLTypeIDSize int = 50
6465
// TypeObject is a string with value object
6566
TypeObject string = "Object"
6667
// TypeEnum is a variable type enum
@@ -82,7 +83,8 @@ const (
8283
// DirectiveDefault is used to add default key
8384
DirectiveDefault string = "default"
8485

85-
// DefaultIndexName string = ""
86+
// DirectiveVarcharSize denotes the maximum allowable character for field type ID
87+
DirectiveVarcharSize string = "size"
8688

8789
// DefaultIndexSort specifies default order of sorting
8890
DefaultIndexSort string = "asc"
@@ -97,6 +99,7 @@ type InspectorFieldType struct {
9799
FieldNull string `db:"Null"`
98100
FieldKey string `db:"Key"`
99101
FieldDefault string `db:"Default"`
102+
VarcharSize int `db:"VarcharSize"`
100103
}
101104

102105
// ForeignKeysType is the type for storing foreignkeys information of sql inspection

gateway/modules/crud/mgo/integration_collections_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestSQL_GetCollections(t *testing.T) {
5656

5757
for _, tt := range tests {
5858
t.Run(tt.name, func(t *testing.T) {
59-
got, err := db.GetCollections(ctx)
59+
got, err := db.GetCollections(context.Background())
6060
if (err != nil) != tt.wantErr {
6161
t.Errorf("GetCollections() error = %v, wantErr %v", err, tt.wantErr)
6262
}

gateway/modules/crud/mgo/integration_main_test.go

+2-38
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,6 @@ var connection = flag.String("conn", "", "connection string of the database")
2121

2222
func TestMain(m *testing.M) {
2323
flag.Parse()
24-
//var customerTable = `type customers {
25-
// id: ID! @primary
26-
// name: String!
27-
// age: Integer!
28-
// height: Float
29-
// is_prime: Boolean!
30-
// birth_date: DateTime!
31-
// address: JSON!
32-
// }`
33-
//var companiesTable = `type companies {
34-
// id: ID! @primary
35-
// parent : ID!
36-
// name : String!
37-
// established_date : DateTime!
38-
// kind : Integer!
39-
// volume : Float!
40-
// is_public : Boolean!
41-
// description : JSON!
42-
// }`
43-
//var ordersTable = `type orders {
44-
// id: ID! @primary
45-
// order_date: DateTime!
46-
// amount: Integer!
47-
// is_prime: Boolean,
48-
// product_id: String!
49-
// address: JSON!
50-
// stars: Float!
51-
// }`
52-
//var rawBatch = `type raw_batch {
53-
// id: ID! @primary
54-
// score : Integer!
55-
// }`
56-
//var rawQuery = `type raw_query {
57-
// id: ID! @primary
58-
// score : Integer!
59-
// }`
6024

6125
// create sc project
6226
var projectInfo = `{"name":"myproject","id":"myproject","secrets":[{"secret":"27f6a16bf7864c319e01b7511737407d","isPrimary":true}],"aesKey":"MWJkOTE5ZjVmMGRjNGZiMjg4MDQ0NjQ5MDE0ZWM2MDQ=","contextTime":5,"modules":{"db":{},"eventing":{},"userMan":{},"remoteServices":{"externalServices":{}},"fileStore":{"enabled":false,"rules":[]}}}`
@@ -108,12 +72,12 @@ func TestMain(m *testing.M) {
10872

10973
db, err := Init(true, *connection, "myproject")
11074
if err != nil {
111-
helpers.Logger.LogInfo(helpers.GetRequestID(ctx), "Create() Couldn't establishing connection with database", dbType)
75+
helpers.Logger.LogInfo(helpers.GetRequestID(context.Background()), "Create() Couldn't establishing connection with database", map[string]interface{}{"dbType": *dbType})
11276
return
11377
}
11478
// clear data
11579
if err := db.client.Database("myproject").Drop(context.Background()); err != nil {
116-
helpers.Logger.LogInfo(helpers.GetRequestID(ctx), "Create() Couldn't truncate table", err)
80+
helpers.Logger.LogInfo(helpers.GetRequestID(context.Background()), "Create() Couldn't truncate table", map[string]interface{}{"error": err})
11781
}
11882

11983
os.Exit(exitVal)

gateway/modules/crud/mgo/read.go

+2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ func (m *Mongo) Read(ctx context.Context, col string, req *model.ReadRequest) (i
116116
results := []interface{}{}
117117

118118
if len(req.Aggregate) > 0 {
119+
helpers.Logger.LogDebug(helpers.GetRequestID(ctx), "Mongo aggregate", map[string]interface{}{"pipeline": pipeline})
119120
cur, err = collection.Aggregate(ctx, pipeline)
120121
} else {
122+
helpers.Logger.LogDebug(helpers.GetRequestID(ctx), "Mongo query", map[string]interface{}{"find": req.Find, "options": findOptions})
121123
cur, err = collection.Find(ctx, req.Find, findOptions)
122124
}
123125
if err != nil {

gateway/modules/crud/sql/describe.go

+19-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ CASE
3737
WHEN column_default = '1' THEN 'true'
3838
WHEN column_default = '0' THEN 'false'
3939
ELSE coalesce(column_default,'')
40-
END AS 'Default'
40+
END AS 'Default',
41+
coalesce(CHARACTER_MAXIMUM_LENGTH,50) AS 'VarcharSize'
4142
from information_schema.columns
4243
where (table_name,table_schema) = (?,?);`
4344
args = append(args, col, project)
@@ -48,7 +49,9 @@ CASE
4849
WHEN t.constraint_type = 'PRIMARY KEY' THEN 'PRI'
4950
WHEN t.constraint_type = 'UNIQUE' THEN 'UNI'
5051
ELSE ''
51-
END AS "Key"
52+
END AS "Key",
53+
-- Set the null values to 50
54+
coalesce(isc.character_maximum_length,50) AS "VarcharSize"
5255
FROM information_schema.columns isc
5356
left join (select cu.table_schema, cu.table_name, cu.column_name, istc.constraint_type
5457
from information_schema.constraint_column_usage cu
@@ -67,8 +70,10 @@ ORDER BY isc.ordinal_position;`
6770
CASE
6871
WHEN TC.CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 'PRI'
6972
WHEN TC.CONSTRAINT_TYPE = 'UNIQUE' THEN 'UNI'
73+
WHEN TC.CONSTRAINT_TYPE = 'FOREIGN KEY' THEN 'MUL'
7074
ELSE isnull(TC.CONSTRAINT_TYPE,'')
71-
END AS 'Key'
75+
END AS 'Key',
76+
coalesce(c.CHARACTER_MAXIMUM_LENGTH,50) AS 'VarcharSize'
7277
FROM INFORMATION_SCHEMA.COLUMNS AS C
7378
FULL JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS CC
7479
ON C.COLUMN_NAME = CC.COLUMN_NAME
@@ -132,15 +137,17 @@ func (s *SQL) getForeignKeyDetails(ctx context.Context, project, col string) ([]
132137
`
133138
args = append(args, project, col)
134139
case model.SQLServer:
135-
queryString = `SELECT
136-
CCU.TABLE_NAME, CCU.COLUMN_NAME, CCU.CONSTRAINT_NAME, RC.DELETE_RULE,
137-
isnull(KCU.TABLE_NAME,'') AS 'REFERENCED_TABLE_NAME', isnull(KCU.COLUMN_NAME,'') AS 'REFERENCED_COLUMN_NAME'
138-
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
139-
FULL JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
140-
ON CCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
141-
FULL JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
142-
ON KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
143-
WHERE CCU.TABLE_SCHEMA = @p1 AND CCU.TABLE_NAME= @p2 AND KCU.TABLE_NAME= @p3`
140+
queryString = `SELECT
141+
CCU.TABLE_NAME, CCU.COLUMN_NAME, CCU.CONSTRAINT_NAME, RC.DELETE_RULE,
142+
isnull(KCU2.TABLE_NAME,'') AS 'REFERENCED_TABLE_NAME', isnull(KCU2.COLUMN_NAME,'') AS 'REFERENCED_COLUMN_NAME'
143+
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
144+
FUll JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
145+
ON RC.CONSTRAINT_NAME = CCU.CONSTRAINT_NAME
146+
FUll JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
147+
ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME
148+
FUll JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2
149+
ON RC.UNIQUE_CONSTRAINT_NAME = KCU2.CONSTRAINT_NAME
150+
WHERE CCU.TABLE_SCHEMA = @p1 AND CCU.TABLE_NAME= @p2 AND KCU.TABLE_NAME= @p3`
144151
args = append(args, project, col, col)
145152
}
146153
rows, err := s.client.QueryxContext(ctx, queryString, args...)

gateway/modules/crud/sql/integration_collections_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ func TestSQL_GetCollections(t *testing.T) {
4141
if err != nil {
4242
t.Fatal("GetCollections() Couldn't establishing connection with database", dbType)
4343
}
44-
4544
for _, tt := range tests {
4645
t.Run(tt.name, func(t *testing.T) {
47-
got, err := db.GetCollections(ctx)
46+
got, err := db.GetCollections(context.Background())
4847
if (err != nil) != tt.wantErr {
4948
t.Errorf("GetCollections() error = %v, wantErr %v", err, tt.wantErr)
5049
}

gateway/modules/crud/sql/integration_create_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestSQL_Create(t *testing.T) {
241241
if err := rows.MapScan(v); err != nil {
242242
t.Error("Create() Scanning error", err)
243243
}
244-
mysqlTypeCheck(model.DBType(*dbType), rowTypes, v)
244+
mysqlTypeCheck(context.Background(), model.DBType(*dbType), rowTypes, v)
245245
readResult = append(readResult, v)
246246
}
247247
if len(tt.wantReadResult) != len(readResult) {

gateway/modules/crud/sql/integration_delete_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestSQL_Delete(t *testing.T) {
161161
if err := rows.MapScan(v); err != nil {
162162
t.Error("Delete() Scanning error", err)
163163
}
164-
mysqlTypeCheck(model.DBType(*dbType), rowTypes, v)
164+
mysqlTypeCheck(context.Background(), model.DBType(*dbType), rowTypes, v)
165165
readResult = append(readResult, v)
166166
}
167167
if !reflect.DeepEqual(tt.wantReadResult, readResult) {
@@ -232,7 +232,7 @@ func TestSQL_DeleteCollection(t *testing.T) {
232232
if err := rows.MapScan(v); err != nil {
233233
t.Error("DeleteCollection Scanning error", err)
234234
}
235-
mysqlTypeCheck(model.DBType(*dbType), rowTypes, v)
235+
mysqlTypeCheck(context.Background(), model.DBType(*dbType), rowTypes, v)
236236
readResult = append(readResult, v)
237237
}
238238
if !reflect.DeepEqual(tt.wantResult, readResult) {

0 commit comments

Comments
 (0)