Skip to content

Commit 25f5381

Browse files
committedJul 17, 2019
completed enterprise edition
1 parent 47e9c55 commit 25f5381

File tree

12 files changed

+67
-28
lines changed

12 files changed

+67
-28
lines changed
 

‎Dockerfile

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
FROM alpine:3.9
2+
23
WORKDIR /space-cloud
4+
35
# Copy the space-cloud binary from the build context to the container's working directory
4-
# COPY space-cloud .
6+
COPY space-cloud .
7+
58
# COPY space-cloud.yaml .
69
RUN set -ex \
710
&& apk add --no-cache ca-certificates wget \
8-
&& wget http://192.168.43.226:8000/space-cloud \
9-
&& wget http://192.168.43.226:8000/config.yaml \
1011
&& chmod +x space-cloud
12+
1113
ENV PROD=false
1214
ENV PATH="/space-cloud:${PATH}"
13-
EXPOSE 8080
14-
CMD ./space-cloud run --config config.yaml
15+
16+
# ports for the http and https servers
17+
EXPOSE 4242 4244
18+
EXPOSE 4343 4245
19+
20+
# ports for nats
21+
EXPOSE 4222 4248
22+
23+
# ports for gossip and raft
24+
EXPOSE 4232 4234
25+
26+
CMD ./space-cloud run

‎examples/realtime-todo-app/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
77
<title>Page Title</title>
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
9-
<script src="https://spaceuptech.com/downloads/libraries/space-api-v0.9.2.js"></script>
9+
<script src="https://spaceuptech.com/downloads/libraries/space-api-v0.10.1.js"></script>
1010
</head>
1111

1212
<body>
@@ -39,7 +39,7 @@
3939
});
4040
}
4141
// Initialise the API
42-
var api = new Space.API("realtime-todo-app", "http://localhost:8080");
42+
var api = new Space.API('realtime-todo-app', 'http://localhost:8080');
4343
var db = api.Mongo();
4444
var userId = "";
4545
// Login function

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/go-stack/stack v1.8.0 // indirect
99
github.com/golang/protobuf v1.3.2
1010
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
11-
github.com/gorilla/mux v1.7.0
11+
github.com/gorilla/mux v1.7.3
1212
github.com/gorilla/websocket v1.4.0
1313
github.com/hashicorp/memberlist v0.1.4
1414
github.com/hashicorp/raft v1.1.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
6262
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k=
6363
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
6464
github.com/gophercloud/gophercloud v0.0.0-20190126172459-c818fa66e4c8/go.mod h1:3WdhXV3rUYy9p6AUW8d94kr+HS62Y4VL9mBnFxsD8q4=
65-
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
66-
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
65+
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
66+
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
6767
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
6868
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
6969
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=

‎modules/crud/crud.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (m *Module) SetConfig(crud config.Crud) error {
5858
// Initialise a new block
5959
c, err := m.h.InitBlock(utils.DBType(dbType), v.Conn)
6060
if err != nil {
61-
return errors.New("CURD: Error - " + dbType + " could not be initialised")
61+
return errors.New("CURD: Error - " + dbType + " could not be initialised - " + err.Error())
6262
}
6363

6464
if v.IsPrimary {

‎utils/admin/admin.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ func New(nodeID string) *Manager {
2727
// SetConfig sets the admin config
2828
func (m *Manager) SetConfig(admin *config.Admin) {
2929
m.lock.Lock()
30+
defer m.lock.Unlock()
31+
32+
if admin.Operation.Mode > 0 {
33+
// Start the validation process for higher op modes
34+
if err := m.validator.startValidation(m.nodeID, admin.Operation.UserID, admin.Operation.Key, admin.Operation.Mode); err != nil {
35+
admin.Operation.Mode = 0
36+
}
37+
}
38+
3039
m.admin = admin
31-
m.lock.Unlock()
3240
}
3341

3442
// GetConfig returns the adming config

‎utils/admin/operations.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (m *Manager) ValidateSyncOperation(c *config.Config, project *config.Projec
3535
maxProjects = 5
3636
}
3737

38-
if len(c.Projects) == (maxProjects - 1) {
38+
if len(c.Projects) < maxProjects {
3939
return true
4040
}
4141

‎utils/admin/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (v *validator) startValidation(id, userID, key string, mode int) error {
4646
// Sleep for 5 minutes before connecting again
4747
time.Sleep(5 * time.Minute)
4848

49-
// Check if 15 days are lapsed without authorization
49+
// Check if 15 days have lapsed without authorization
5050
if time.Since(timer).Hours() > 24*15 {
5151

5252
// Stop the validation process

‎utils/handlers/config.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,19 @@ func HandleStoreDeploymentConfig(adminMan *admin.Manager, syncMan *syncman.SyncM
186186
defer r.Body.Close()
187187

188188
// Check if the request is authorised
189-
status, err := adminMan.IsAdminOpAuthorised(token, "deploy")
190-
if err != nil {
191-
w.WriteHeader(status)
192-
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
193-
return
189+
if c.Enabled {
190+
status, err := adminMan.IsAdminOpAuthorised(token, "deploy")
191+
if err != nil {
192+
w.WriteHeader(status)
193+
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
194+
return
195+
}
196+
} else {
197+
if err := adminMan.IsTokenValid(token); err != nil {
198+
w.WriteHeader(http.StatusUnauthorized)
199+
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
200+
return
201+
}
194202
}
195203

196204
// Set the deploy config

‎utils/handlers/userman.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ func HandleEmailSignUp(projects *projects.Projects) http.HandlerFunc {
147147

148148
status, result, err := state.UserManagement.EmailSignUp(ctx, dbType, project, req["email"].(string), req["name"].(string), req["pass"].(string), req["role"].(string))
149149
if err != nil {
150+
w.WriteHeader(status)
151+
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
150152
return
151153
}
152-
w.WriteHeader(status)
154+
155+
w.WriteHeader(http.StatusOK)
153156
json.NewEncoder(w).Encode(result)
154157
}
155158
}

‎utils/projects/store.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package projects
22

3-
import "github.com/spaceuptech/space-cloud/config"
3+
import (
4+
"log"
5+
6+
"github.com/spaceuptech/space-cloud/config"
7+
)
48

59
// StoreProject stores the provided project config
610
func (p *Projects) StoreProject(config *config.Project) error {
@@ -17,24 +21,28 @@ func (p *Projects) StoreProject(config *config.Project) error {
1721
state.UserManagement.SetConfig(config.Modules.Auth)
1822

1923
if err := state.Static.SetConfig(config.Modules.Static); err != nil {
20-
return err
24+
log.Println("Static module config error:", err)
2125
}
2226

2327
// Set the configuration for the file storage module
2428
if err := state.FileStore.SetConfig(config.Modules.FileStore); err != nil {
25-
return err
29+
log.Println("File storage module config error:", err)
2630
}
2731

2832
// Set the configuration for the functions module
2933
if err := state.Functions.SetConfig(config.Modules.Functions); err != nil {
30-
return err
34+
log.Println("Functions module config error:", err)
3135
}
3236

3337
// Set the configuration for the Realtime module
3438
if err := state.Realtime.SetConfig(config.ID, config.Modules.Realtime); err != nil {
35-
return err
39+
log.Println("Realtime module config error:", err)
3640
}
3741

3842
// Set the configuration for the crud module
39-
return state.Crud.SetConfig(config.Modules.Crud)
43+
if err := state.Crud.SetConfig(config.Modules.Crud); err != nil {
44+
log.Println("Database module config error:", err)
45+
}
46+
47+
return nil
4048
}

‎utils/syncman/raft.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *SyncManager) Apply(l *raft.Log) interface{} {
9595
found = true
9696
}
9797
}
98-
if !found && len(s.projectConfig.Projects) == 0 {
98+
if !found {
9999
s.projectConfig.Projects = append(s.projectConfig.Projects, c.Project)
100100
}
101101
// Write the config to file
@@ -107,7 +107,7 @@ func (s *SyncManager) Apply(l *raft.Log) interface{} {
107107
case utils.RaftCommandDelete:
108108
for i, p := range s.projectConfig.Projects {
109109
if p.ID == c.ID {
110-
remove(s.projectConfig.Projects, i)
110+
s.projectConfig.Projects = remove(s.projectConfig.Projects, i)
111111
break
112112
}
113113
}

0 commit comments

Comments
 (0)
Please sign in to comment.