Skip to content

Commit 4c3b7c1

Browse files
authored
Merge pull request #166 from gravitl/feature_v0.5_clientgrpc
Feature v0.5 clientgrpc
2 parents 77d0ed7 + f757b9e commit 4c3b7c1

File tree

21 files changed

+236
-161
lines changed

21 files changed

+236
-161
lines changed

compose/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
ports:
4545
- "80:80"
4646
environment:
47-
BACKEND_URL: "http://3.235.190.90:8081"
47+
BACKEND_URL: "http://HOST_IP:8081"
4848
coredns:
4949
depends_on:
5050
- netmaker

config/dnsconfig/netmaker.hosts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.10.10.1 nethub.default
1+
10.10.10.1 netmaker.default

controllers/intClientHttpController.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package controller
22

33
import (
4-
// "fmt"
4+
// "fmt"
5+
// "github.com/davecgh/go-spew/spew"
56
"errors"
67
"context"
78
"encoding/json"
@@ -21,7 +22,6 @@ func intClientHandlers(r *mux.Router) {
2122
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(getIntClient))).Methods("GET")
2223
r.HandleFunc("/api/intclients", securityCheck(http.HandlerFunc(getAllIntClients))).Methods("GET")
2324
r.HandleFunc("/api/intclients/deleteall", securityCheck(http.HandlerFunc(deleteAllIntClients))).Methods("DELETE")
24-
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(deleteIntClient))).Methods("DELETE")
2525
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(updateIntClient))).Methods("PUT")
2626
r.HandleFunc("/api/intclient/register", http.HandlerFunc(registerIntClient)).Methods("POST")
2727
r.HandleFunc("/api/intclient/{clientid}", http.HandlerFunc(deleteIntClient)).Methods("DELETE")
@@ -138,25 +138,29 @@ func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
138138
client.Address = newAddress
139139
}
140140
if client.Network == "" { client.Network = "comms" }
141-
142-
wgconfig := servercfg.GetWGConfig()
143-
client.ServerPublicEndpoint = servercfg.GetAPIHost()
144-
client.ServerAPIPort = servercfg.GetAPIPort()
145-
client.ServerPrivateAddress = wgconfig.GRPCWGAddress
146-
client.ServerWGPort = wgconfig.GRPCWGPort
147-
client.ServerGRPCPort = servercfg.GetGRPCPort()
141+
server, err := serverctl.GetServerWGConf()
142+
//spew.Dump(server)
143+
if err != nil {
144+
return client, err
145+
}
146+
client.ServerPublicEndpoint = server.ServerPublicEndpoint
147+
client.ServerAPIPort = server.ServerAPIPort
148+
client.ServerPrivateAddress = server.ServerPrivateAddress
149+
client.ServerWGPort = server.ServerWGPort
150+
client.ServerGRPCPort = server.ServerGRPCPort
151+
client.ServerKey = server.ServerKey
148152

149153
if client.ClientID == "" {
150154
clientid := StringWithCharset(7, charset)
151155
clientname := "client-" + clientid
152156
client.ClientID = clientname
153157
}
154158

155-
159+
//spew.Dump(client)
156160
collection := mongoconn.Client.Database("netmaker").Collection("intclients")
157161
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
158162
// insert our network into the network table
159-
_, err := collection.InsertOne(ctx, client)
163+
_, err = collection.InsertOne(ctx, client)
160164
defer cancel()
161165

162166
if err != nil {

controllers/nodeGrpcController.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package controller
33
import (
44
"context"
55
"fmt"
6-
6+
"log"
77
"github.com/gravitl/netmaker/functions"
88
nodepb "github.com/gravitl/netmaker/grpc"
99
"github.com/gravitl/netmaker/models"
@@ -162,7 +162,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
162162
if err != nil {
163163
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("Could not find network: %v", err))
164164
} else {
165-
fmt.Println("Creating node in network " + network.NetID)
165+
log.Println("Creating node in network " + network.NetID)
166166
}
167167

168168
if !validKey {
@@ -356,7 +356,6 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
356356
}
357357

358358
func (s *NodeServiceServer) DeleteNode(ctx context.Context, req *nodepb.DeleteNodeReq) (*nodepb.DeleteNodeRes, error) {
359-
fmt.Println("beginning node delete")
360359
macaddress := req.GetMacaddress()
361360
network := req.GetNetworkName()
362361

controllers/serverHttpController.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func serverHandlers(r *mux.Router) {
1515
r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(http.HandlerFunc(addNetwork))).Methods("POST")
1616
r.HandleFunc("/api/server/getconfig", securityCheckServer(http.HandlerFunc(getConfig))).Methods("GET")
17+
r.HandleFunc("/api/server/getwgconfig", securityCheckServer(http.HandlerFunc(getWGConfig))).Methods("GET")
1718
r.HandleFunc("/api/server/removenetwork/{network}", securityCheckServer(http.HandlerFunc(removeNetwork))).Methods("DELETE")
1819
}
1920

@@ -84,11 +85,35 @@ func getConfig(w http.ResponseWriter, r *http.Request) {
8485

8586
// get params
8687

87-
scfg := servercfg.GetConfig()
88+
scfg := servercfg.GetServerConfig()
8889
w.WriteHeader(http.StatusOK)
8990
json.NewEncoder(w).Encode(scfg)
9091
}
9192

93+
func getWGConfig(w http.ResponseWriter, r *http.Request) {
94+
// Set header
95+
w.Header().Set("Content-Type", "application/json")
96+
97+
// get params
98+
99+
wgcfg := servercfg.GetWGConfig()
100+
w.WriteHeader(http.StatusOK)
101+
json.NewEncoder(w).Encode(wgcfg)
102+
}
103+
104+
/*
105+
func getMongoConfig(w http.ResponseWriter, r *http.Request) {
106+
// Set header
107+
w.Header().Set("Content-Type", "application/json")
108+
109+
// get params
110+
111+
mcfg := servercfg.GetMongoConfig()
112+
w.WriteHeader(http.StatusOK)
113+
json.NewEncoder(w).Encode(mcfg)
114+
}
115+
*/
116+
92117
func addNetwork(w http.ResponseWriter, r *http.Request) {
93118
// Set header
94119
w.Header().Set("Content-Type", "application/json")

functions/helpers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ func CreateServerToken(netID string) (string, error) {
4444
if *network.IsLocal {
4545
privAddr = network.LocalRange
4646
}
47-
48-
accessstringdec := " " + "|"+ address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
47+
accessstringdec := address + "|"+ address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
4948

5049
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
5150

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/gravitl/netmaker/serverctl"
1111
"github.com/gravitl/netmaker/mongoconn"
1212
"github.com/gravitl/netmaker/functions"
13-
"fmt"
1413
"os"
1514
"os/exec"
1615
"net"
@@ -33,12 +32,12 @@ func main() {
3332
output, err := cmd.Output()
3433

3534
if err != nil {
36-
fmt.Println("Error running 'id -u' for prereq check. Please investigate or disable client mode.")
35+
log.Println("Error running 'id -u' for prereq check. Please investigate or disable client mode.")
3736
log.Fatal(err)
3837
}
3938
i, err := strconv.Atoi(string(output[:len(output)-1]))
4039
if err != nil {
41-
fmt.Println("Error retrieving uid from 'id -u' for prereq check. Please investigate or disable client mode.")
40+
log.Println("Error retrieving uid from 'id -u' for prereq check. Please investigate or disable client mode.")
4241
log.Fatal(err)
4342
}
4443
if i != 0 {
@@ -147,7 +146,7 @@ func runGRPC(wg *sync.WaitGroup, installserver bool) {
147146
log.Println("Agent Server succesfully started on port " + grpcport + " (gRPC)")
148147

149148
if installserver {
150-
fmt.Println("Adding server to default network")
149+
log.Println("Adding server to default network")
151150
success, err := serverctl.AddNetwork("default")
152151
if err != nil {
153152
log.Printf("Error adding to default network: %v", err)

models/intclient.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package models
22

33
type IntClient struct {
4-
ClientID string `json:"clientid" bson:"clientid"`
5-
PrivateKey string `json:"privatekey" bson:"privatekey"`
6-
PublicKey string `json:"publickey" bson:"publickey"`
7-
AccessKey string `json:"accesskey" bson:"accesskey"`
8-
Address string `json:"address" bson:"address"`
9-
Address6 string `json:"address6" bson:"address6"`
10-
Network string `json:"network" bson:"network"`
11-
ServerPublicEndpoint string `json:"serverwgendpoint" bson:"serverwgendpoint"`
12-
ServerAPIPort string `json:"serverapiendpoint" bson:"serverapiendpoint"`
13-
ServerPrivateAddress string `json:"serveraddress" bson:"serveraddress"`
14-
ServerWGPort string `json:"serverport" bson:"serverport"`
15-
ServerGRPCPort string `json:"serverport" bson:"serverport"`
16-
ServerKey string `json:"serverkey" bson:"serverkey"`
17-
IsServer string `json:"isserver" bson:"isserver"`
4+
ClientID string `json:"clientid" bson:"clientid"`
5+
PrivateKey string `json:"privatekey" bson:"privatekey"`
6+
PublicKey string `json:"publickey" bson:"publickey"`
7+
AccessKey string `json:"accesskey" bson:"accesskey"`
8+
Address string `json:"address" bson:"address"`
9+
Address6 string `json:"address6" bson:"address6"`
10+
Network string `json:"network" bson:"network"`
11+
ServerPublicEndpoint string `json:"serverpublicendpoint" bson:"serverpublicendpoint"`
12+
ServerAPIPort string `json:"serverapiport" bson:"serverapiport"`
13+
ServerPrivateAddress string `json:"serverprivateaddress" bson:"serverprivateaddress"`
14+
ServerWGPort string `json:"serverwgport" bson:"serverwgport"`
15+
ServerGRPCPort string `json:"servergrpcport" bson:"servergrpcport"`
16+
ServerKey string `json:"serverkey" bson:"serverkey"`
17+
IsServer string `json:"isserver" bson:"isserver"`
1818
}

netclient/command/commands.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ func Uninstall(cfg config.GlobalConfig) error {
135135
err = functions.Unregister(cfg)
136136
return err
137137
}
138-
func Reregister(cfg config.GlobalConfig) error {
139-
err := functions.Reregister(cfg)
140-
return err
141-
}
142138
func Unregister(cfg config.GlobalConfig) error {
143139
err := functions.Unregister(cfg)
144140
return err

netclient/config/config.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ func ModGlobalConfig(cfg models.IntClient) error{
273273
if cfg.ServerKey != ""{
274274
modconfig.Client.ServerKey = cfg.ServerKey
275275
}
276+
if cfg.AccessKey != ""{
277+
modconfig.Client.AccessKey = cfg.AccessKey
278+
}
279+
if cfg.ClientID != ""{
280+
modconfig.Client.ClientID = cfg.ClientID
281+
}
282+
276283
err = WriteGlobal(&modconfig)
277284
return err
278285
}
@@ -369,13 +376,14 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, error){
369376
}
370377
token := string(tokenbytes)
371378
tokenvals := strings.Split(token, "|")
372-
cfg.Server.GRPCAddress = tokenvals[1]
373-
cfg.Server.APIAddress = tokenvals[2]
374-
cfg.Network = tokenvals[3]
375-
cfg.Node.Network = tokenvals[4]
376-
cfg.Server.AccessKey = tokenvals[5]
377-
cfg.Node.LocalRange = tokenvals[6]
378379

380+
cfg.Server.GRPCAddress = tokenvals[1]
381+
cfg.Network = tokenvals[3]
382+
cfg.Node.Network = tokenvals[3]
383+
cfg.Server.AccessKey = tokenvals[4]
384+
if len(tokenvals) > 5 {
385+
cfg.Node.LocalRange = tokenvals[5]
386+
}
379387
if c.String("grpcserver") != "" {
380388
cfg.Server.GRPCAddress = c.String("grpcserver")
381389
}
@@ -405,22 +413,22 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, error){
405413
cfg.Node.Password = c.String("password")
406414
cfg.Node.MacAddress = c.String("macaddress")
407415
cfg.Node.LocalAddress = c.String("localaddress")
408-
cfg.Node.LocalRange = c.String("localrange")
409416
cfg.Node.WGAddress = c.String("address")
410417
cfg.Node.WGAddress6 = c.String("addressIPV6")
411-
cfg.Node.Roaming = c.String("")
412-
cfg.Node.DNS = c.String("")
413-
cfg.Node.IsLocal = c.String("")
414-
cfg.Node.IsDualStack = c.String("")
415-
cfg.Node.IsIngressGateway = c.String("")
416-
cfg.Node.PostUp = c.String("")
417-
cfg.Node.PostDown = c.String("")
418-
cfg.Node.Port = int32(c.Int(""))
419-
cfg.Node.KeepAlive = int32(c.Int(""))
420-
cfg.Node.PublicKey = c.String("")
421-
cfg.Node.PrivateKey = c.String("")
422-
cfg.Node.Endpoint = c.String("")
423-
cfg.Node.IPForwarding = c.String("")
418+
cfg.Node.Roaming = c.String("roaming")
419+
cfg.Node.DNS = c.String("dns")
420+
cfg.Node.IsLocal = c.String("islocal")
421+
cfg.Node.IsDualStack = c.String("isdualstack")
422+
cfg.Node.PostUp = c.String("postup")
423+
cfg.Node.PostDown = c.String("postdown")
424+
cfg.Node.Port = int32(c.Int("port"))
425+
cfg.Node.KeepAlive = int32(c.Int("keepalive"))
426+
cfg.Node.PublicKey = c.String("publickey")
427+
cfg.Node.PrivateKey = c.String("privatekey")
428+
cfg.Node.Endpoint = c.String("endpoint")
429+
cfg.Node.IPForwarding = c.String("ipforwarding")
430+
cfg.OperatingSystem = c.String("operatingsystem")
431+
cfg.Daemon = c.String("daemon")
424432

425433
return cfg, nil
426434
}
@@ -531,4 +539,3 @@ func FileExists(f string) bool {
531539
}
532540
return !info.IsDir()
533541
}
534-

0 commit comments

Comments
 (0)