diff --git a/.gitignore b/.gitignore index 07aabdd..6fbe483 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,4 @@ fabric.properties .glide/ .idea/ *.iml +.vendor/ \ No newline at end of file diff --git a/proxy/noauthagent/agent_service.go b/proxy/noauthagent/agent_service.go new file mode 100644 index 0000000..4e4ece5 --- /dev/null +++ b/proxy/noauthagent/agent_service.go @@ -0,0 +1,109 @@ +package noauthagent + +import ( + "github.com/google/uuid" + "git.loafle.net/overflow/commons_go/model/timestamp" + "git.loafle.net/overflow/overflow_proxy_service/proxy" + "encoding/json" +) + +type NoAuthAgentService struct { + +} + +func NewNoAuthAgentService() *NoAuthAgentService { + return &NoAuthAgentService{} +} + + +type NoAuthAgent struct { + Id json.Number `json:"id,Number,omitempty"` + TempKey string `json:"tempKey,omitempty"` + Date timestamp.Timestamp`json:"date,omitempty"` + ApiKey string `json:"apiKey,omitempty"` + AuthStatus string `json:"authStatus,omitempty"` + LocalIP int64 `json:"localIP,omitempty"` + HostName string `json:"hostName,omitempty"` +} + +func NewNoAuthAgent(apikey string, localIp int64, hostName string) *NoAuthAgent { + + na := &NoAuthAgent{ + Date:timestamp.Now(), + ApiKey:apikey, + LocalIP:localIp, + HostName:hostName, + } + return na +} + +func(as *NoAuthAgentService)CreateTempKey(na *NoAuthAgent) (error) { + + uu, err := uuid.NewUUID(); + + if err != nil { + return err + } + + na.TempKey = uu.String() + + return nil +} + +func(as *NoAuthAgentService)SaveNoAuthAgent(na *NoAuthAgent) (string, error) { + + + bytes, err := json.Marshal(na) + if err != nil { + return "",err + } + + memMap := make(map[string]string) + memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes); + + out := proxy.InvokeDB("noauthAgent", "create", memMap); + + return out, nil; +} + +func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) { + + memMap := make(map[string]string) + + na := NewNoAuthAgent("", 0, "") + na.TempKey = tempKey + + bytes, err := json.Marshal(na) + if err != nil { + return "", err; + } + + memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes); + + out := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap); + + + return out,nil; +} + + +func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) { + + memMap := make(map[string]string) + + na := NewNoAuthAgent("", 0, "") + na.AuthStatus = authStatus + + bytes, err := json.Marshal(na) + if err != nil { + return "", err; + } + + memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes); + + out := proxy.InvokeDB("noauthAgent", "findAllByNoAuth", memMap); + + + return out,nil; +} + diff --git a/proxy/noauthagent/agent_service_test.go b/proxy/noauthagent/agent_service_test.go new file mode 100644 index 0000000..006cc69 --- /dev/null +++ b/proxy/noauthagent/agent_service_test.go @@ -0,0 +1,75 @@ +package noauthagent + + +import ( + "github.com/google/uuid" + "testing" + +) + + +func TestCreateUUid(t *testing.T) { + + uu, err := uuid.NewUUID() + + if err != nil { + t.Fatal(err) + } + + t.Log(uu) + +} + +func TestCreateNoAuthAgent(t *testing.T) { + + na := NewNoAuthAgent("2334278390283", 111, "Snoop") + + na.TempKey = "22222222" + na.AuthStatus = "WAIT" + + nas := NewNoAuthAgentService() + + out, err := nas.SaveNoAuthAgent(na) + + if err != nil { + t.Fatal(err) + } + + t.Log(out) + +} + +func TestCheckAuthNoAuthAgent(t *testing.T) { + + na := NewNoAuthAgent("2334278390283", 111, "Snoop") + + na.TempKey = "alsdkjf;alkdjsf;la" + na.AuthStatus = "WAIT" + + nas := NewNoAuthAgentService() + + out, err := nas.CheckAuth(na.TempKey) + + if err != nil { + t.Fatal(err) + } + + t.Log(out) + // +} + + +func TestNoAuthList(t *testing.T) { + + + nas := NewNoAuthAgentService() + + out, err := nas.GetNoAuthList("ACCEPT") + + if err != nil { + t.Fatal(err) + } + + t.Log(out) + +} \ No newline at end of file diff --git a/proxy/service.go b/proxy/service.go index 15275f8..460f615 100644 --- a/proxy/service.go +++ b/proxy/service.go @@ -14,7 +14,7 @@ func InvokeDB(targetDb, methodName string, param map[string]string) (string) { in.Method = methodName in.Param = param - conn, err := grpc.Dial("192.168.1.105:50006", grpc.WithInsecure()) + conn, err := grpc.Dial("192.168.1.209:50006", grpc.WithInsecure()) if err != nil { log.Fatal("Rpc Error: ", err)