Skip to content

Commit

Permalink
major overhaul initiated
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiszli committed May 25, 2021
1 parent 82d430d commit 78ae219
Show file tree
Hide file tree
Showing 37 changed files with 3,046 additions and 1,829 deletions.
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var Config *EnvironmentConfig
type EnvironmentConfig struct {
Server ServerConfig `yaml:"server"`
MongoConn MongoConnConfig `yaml:"mongoconn"`
WG WG `yaml:"wg"`
}

// ServerConfig :
Expand All @@ -48,6 +49,18 @@ type ServerConfig struct {
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
}

type WG struct {
RegisterKeyRequired string `yaml:"keyrequired"`
GRPCWireGuard string `yaml:"grpcwg"`
GRPCWGInterface string `yaml:"grpciface"`
GRPCWGAddress string `yaml:"grpcaddr"`
GRPCWGAddressRange string `yaml:"grpcaddrrange"`
GRPCWGEndpoint string `yaml:"grpcendpoint"`
GRPCWGPort string `yaml:"grpcport"`
GRPCWGPubKey string `yaml:"pubkey"`
GRPCWGPrivKey string `yaml:"privkey"`
}

type MongoConnConfig struct {
User string `yaml:"user"`
Pass string `yaml:"pass"`
Expand Down
Binary file added controllers/.serverClient.go.swp
Binary file not shown.
1 change: 1 addition & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func GetPeersList(networkName string) ([]models.PeersResponse, error) {
return peers, err
}


func GetExtPeersList(networkName string, macaddress string) ([]models.ExtPeersResponse, error) {

var peers []models.ExtPeersResponse
Expand Down
233 changes: 0 additions & 233 deletions controllers/externalHttpController.go.backup

This file was deleted.

26 changes: 26 additions & 0 deletions controllers/networkHttpController.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func networkHandlers(r *mux.Router) {
r.HandleFunc("/api/networks/{networkname}/keyupdate", securityCheck(http.HandlerFunc(keyUpdate))).Methods("POST")
r.HandleFunc("/api/networks/{networkname}/keys", securityCheck(http.HandlerFunc(createAccessKey))).Methods("POST")
r.HandleFunc("/api/networks/{networkname}/keys", securityCheck(http.HandlerFunc(getAccessKeys))).Methods("GET")
r.HandleFunc("/api/networks/{networkname}/signuptoken", securityCheck(http.HandlerFunc(getSignupToken))).Methods("GET")
r.HandleFunc("/api/networks/{networkname}/keys/{name}", securityCheck(http.HandlerFunc(deleteAccessKey))).Methods("DELETE")
}

Expand Down Expand Up @@ -640,6 +641,31 @@ func CreateAccessKey(accesskey models.AccessKey, network models.Network) (models
return accesskey, nil
}

func GetSignupToken(netID string) (models.AccessKey, error) {

var accesskey models.AccessKey
address := servercfg.GetGRPCHost() + ":" + servercfg.GetGRPCPort()

accessstringdec := address + "|" + netID + "|" + "" + "|"
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
return accesskey, nil
}
func getSignupToken(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var params = mux.Vars(r)
netID := params["networkname"]

token, err := GetSignupToken(netID)
if err != nil {
returnErrorResponse(w, r, formatError(err, "internal"))
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(token)
}



//pretty simple get
func getAccessKeys(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
Expand Down
51 changes: 51 additions & 0 deletions controllers/nodeGrpcController.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,57 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
return response, nil
}

func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*nodepb.Client, error) {
// Get the protobuf node type from the protobuf request type
// Essentially doing req.Node to access the struct with a nil check
// Now we have to convert this into a NodeItem type to convert into BSON
clientreq := models.ServerClient{
// ID: primitive.NilObjectID,
Address: data.GetAddress(),
Address6: data.GetAddress6(),
AccessKey: data.GetAccesskey(),
PublicKey: data.GetPublickey(),
PrivateKey: data.GetPrivatekey(),
ServerPort: data.GetServerport(),
ServerKey: data.GetServerkey(),
ServerEndpoint: data.GetServerendpoint(),
}

//Check to see if key is valid
//TODO: Triple inefficient!!! This is the third call to the DB we make for networks
if servercfg.IsRegisterKeyRequired() {
validKey := functions.IsKeyValidGlobal(clientreq.AccessKey)
if !validKey {
return nil, status.Errorf(
codes.Internal,
fmt.Sprintf("Invalid key, and server does not allow no-key signups"),
)
}
}
client, err := RegisterClient(clientreq)

if err != nil {
// return internal gRPC error to be handled later
return nil, status.Errorf(
codes.Internal,
fmt.Sprintf("Internal error: %v", err),
)
}
// return the node in a CreateNodeRes type
response := &nodepb.Client{
Privatekey: client.PrivateKey,
Publickey: client.PublicKey,
Accesskey: client.AccessKey,
Address: client.Address,
Address6: client.Address6,
Serverendpoint: client.ServerEndpoint,
Serverport: client.ServerPort,
Serverkey: client.ServerKey,
}

return response, nil
}

func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNodeReq) (*nodepb.CreateNodeRes, error) {
// Get the protobuf node type from the protobuf request type
// Essentially doing req.Node to access the struct with a nil check
Expand Down
1 change: 1 addition & 0 deletions controllers/nodeHttpController.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func nodeHandlers(r *mux.Router) {
r.HandleFunc("/api/nodes/{network}/{macaddress}/deleteingress", securityCheck(http.HandlerFunc(deleteIngressGateway))).Methods("DELETE")
r.HandleFunc("/api/nodes/{network}/{macaddress}/approve", authorize(true, "master", http.HandlerFunc(uncordonNode))).Methods("POST")
r.HandleFunc("/api/nodes/{network}", createNode).Methods("POST")
//r.HandleFunc("/api/register", registerClient).Methods("POST")
r.HandleFunc("/api/nodes/adm/{network}/lastmodified", authorize(true, "network", http.HandlerFunc(getLastModified))).Methods("GET")
r.HandleFunc("/api/nodes/adm/{network}/authenticate", authenticate).Methods("POST")

Expand Down
Loading

0 comments on commit 78ae219

Please sign in to comment.