fixed client side for multinet and added group filter to query params server side.

This commit is contained in:
afeiszli
2021-04-05 11:06:30 -04:00
parent 0080e9a2ee
commit 1f377997cb
9 changed files with 229 additions and 127 deletions

View File

@@ -14,17 +14,17 @@ import (
)
// CreateJWT func will used to create the JWT while signing in and signing out
func SetJWT(client nodepb.NodeServiceClient) (context.Context, error) {
func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) {
//home, err := os.UserHomeDir()
home := "/etc/netclient"
tokentext, err := ioutil.ReadFile(home + "/.nettoken")
tokentext, err := ioutil.ReadFile(home + "/nettoken")
if err != nil {
fmt.Println("Error reading token. Logging in to retrieve new token.")
err = AutoLogin(client)
err = AutoLogin(client, network)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong with Auto Login: %v", err))
}
tokentext, err = ioutil.ReadFile(home + "/.nettoken")
tokentext, err = ioutil.ReadFile(home + "/nettoken")
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong: %v", err))
}
@@ -38,13 +38,17 @@ func SetJWT(client nodepb.NodeServiceClient) (context.Context, error) {
return ctx, nil
}
func AutoLogin(client nodepb.NodeServiceClient) error {
func AutoLogin(client nodepb.NodeServiceClient, network string) error {
//home, err := os.UserHomeDir()
home := "/etc/netclient"
nodecfg := config.Config.Node
login := &nodepb.LoginRequest{
Password: nodecfg.Password,
Macaddress: nodecfg.MacAddress,
//nodecfg := config.Config.Node
config, err := config.ReadConfig(network)
if err != nil {
return err
}
login := &nodepb.LoginRequest{
Password: config.Node.Password,
Macaddress: config.Node.MacAddress,
}
// RPC call
res, err := client.Login(context.TODO(), login)
@@ -52,7 +56,7 @@ func AutoLogin(client nodepb.NodeServiceClient) error {
return err
}
tokenstring := []byte(res.Accesstoken)
err = ioutil.WriteFile(home + "/.nettoken", tokenstring, 0644)
err = ioutil.WriteFile(home + "/nettoken", tokenstring, 0644)
if err != nil {
return err
}