From 3b95f90a1d01d1d2b3d3c4f65bd4fba016567c15 Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 5 Jun 2017 19:59:10 +0900 Subject: [PATCH 01/10] added target service test --- proxy/target/target_service.go | 6 +- proxy/target/target_service_test.go | 125 +++++++++++++++++++++++++++- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/proxy/target/target_service.go b/proxy/target/target_service.go index 071c4be..3eabc7c 100644 --- a/proxy/target/target_service.go +++ b/proxy/target/target_service.go @@ -16,7 +16,7 @@ type Target struct { Kinds string `json:"kinds,omitempty"` Version string `json:"version,omitempty"` CreateDate timestamp.Timestamp `json:"createDate,omitempty"` - Member *member.MemberService `json:"member,omitempty"` + Member *member.Member `json:"member,omitempty"` } type TargetService struct { @@ -27,6 +27,10 @@ func NewTargetService() *TargetService { return &TargetService{} } +func (t *TargetService)GetModel() interface{} { + return &Target{} +} + func (t *TargetService)List(tm *Target) string { bytes, err := json.Marshal(tm) diff --git a/proxy/target/target_service_test.go b/proxy/target/target_service_test.go index c949e12..a800551 100644 --- a/proxy/target/target_service_test.go +++ b/proxy/target/target_service_test.go @@ -6,6 +6,8 @@ import ( "git.loafle.net/overflow/overflow_proxy_service/proxy/member" + "reflect" + "fmt" ) func TestCreateTarget(t *testing.T) { @@ -18,7 +20,7 @@ func TestCreateTarget(t *testing.T) { Kinds:"PostgreSQL", Version:"9.5.0", VendorName:"PostgreSQL 9.5.0", - Member:&member.MemberService{Id:"1"}, + Member:&member.Member{Id:"1"}, } ts := NewTargetService() @@ -32,7 +34,7 @@ func TestCreateTarget(t *testing.T) { func TestFindAll(t *testing.T) { tt := Target{ - Member:&member.MemberService{Id:"1"}, + Member:&member.Member{Id:"1"}, } ts := NewTargetService() @@ -41,3 +43,122 @@ func TestFindAll(t *testing.T) { str := ts.List(&tt) t.Log(str) } + +type MyInt int +func TestRefloect(t *testing.T) { + + f := &Foo{ + FirstName: "Drew", + LastName: "Olson", + Age: 30, + } + + f.reflect() +} + +type Foo struct { + FirstName string `tag_name:"tag 1"` + LastName string `tag_name:"tag 2"` + Age int `tag_name:"tag 3"` +} + +func (f *Foo) reflect() { + val := reflect.ValueOf(f).Elem() + + for i := 0; i < val.NumField(); i++ { + valueField := val.Field(i) + typeField := val.Type().Field(i) + tag := typeField.Tag + + fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", typeField.Name, valueField.Interface(), tag.Get("tag_name")) + } + + for j := 0; j < val.NumMethod(); j++ { + + v := val.Method(j) + method := val.Type().Method(j) + + fmt.Println(v) + fmt.Println(method) + + } +} + + +type YourT1 struct {} +func (y YourT1) MethodBar() { + //do something +} + +type YourT2 struct {} +func (y YourT2) MethodFoo(i int, oo string) { + //do something +} + +func Invoke(any interface{}, name string, args... interface{}) { + inputs := make([]reflect.Value, len(args)) + for i, _ := range args { + inputs[i] = reflect.ValueOf(args[i]) + } + reflect.ValueOf(any).MethodByName(name).Call(inputs) +} + +func TestRelfect02(t *testing.T) { + + + + Invoke(YourT2{}, "MethodFoo", 10, "abc") + Invoke(YourT1{}, "MethodBar") +} + +type Aaa struct { + a string +} + +type Bbb struct { + b int +} + +type Handler struct{} + +func (h Handler) GET(a Aaa, b Bbb, ptr *Aaa) string { + return "OK" + a.a + " ptr:" + ptr.a +} + +func TestReflect03(t *testing.T) { + handler := new(Handler) + + objects := make(map[reflect.Type]interface{}) + objects[reflect.TypeOf(Aaa{})] = Aaa{"jkljkL"} + objects[reflect.TypeOf(new(Aaa))] = &Aaa{"pointer!"} + objects[reflect.TypeOf(Bbb{})] = Bbb{} + + //in := make([]reflect.Value, 0) + method := reflect.ValueOf(handler).MethodByName("GET") + + fmt.Println(method) + + in := make([]reflect.Value, method.Type().NumIn()) + + fmt.Println("method type num in:", method.Type().NumIn()) + for i := 0; i < method.Type().NumIn(); i++ { + t := method.Type().In(i) + + if i == 0 { + intPtr := reflect.New(t) + a := intPtr.Elem().Interface().(Aaa) + a.a = "aaaddsasdf" + fmt.Println(a) + } + + fmt.Println(t) + object := objects[t] + fmt.Println(i, "->", object) + in[i] = reflect.ValueOf(object) + } + + fmt.Println("method type num out:", method.Type().NumOut()) + + response := method.Call(in) + fmt.Println(response) +} \ No newline at end of file From 9e178bd8ffdb62e570f7bcb227a528cc65bbcc2e Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 5 Jun 2017 21:11:04 +0900 Subject: [PATCH 02/10] noauthagent auth process --- proxy/noauthagent/agent_service.go | 39 +++++++++++++++++++++++-- proxy/noauthagent/agent_service_test.go | 21 +++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/proxy/noauthagent/agent_service.go b/proxy/noauthagent/agent_service.go index 1310ae8..e782101 100644 --- a/proxy/noauthagent/agent_service.go +++ b/proxy/noauthagent/agent_service.go @@ -5,6 +5,9 @@ import ( "git.loafle.net/overflow/commons_go/model/timestamp" "git.loafle.net/overflow/overflow_proxy_service/proxy" "encoding/json" + "git.loafle.net/overflow/overflow_proxy_service/proxy/member" + "git.loafle.net/overflow/overflow_proxy_service/proxy/agent" + "github.com/reactivex/rxgo/errors" ) type NoAuthAgentService struct { @@ -77,12 +80,12 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) { } -func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) { +func(as *NoAuthAgentService)GetNoAuthList(excludeStatus string) (string,error) { memMap := make(map[string]string) na := NewNoAuthAgent("", 0, "") - na.AuthStatus = authStatus + na.AuthStatus = excludeStatus bytes, err := json.Marshal(na) if err != nil { @@ -101,3 +104,35 @@ func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) { func (as *NoAuthAgentService) GetModel() (interface{}) { return NewNoAuthAgent("", 0, "") } + +func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc string) (string, error) { + paramMap := make(map[string]string) + noauthAgt.AuthStatus = "ACCEPT" + + bytes, err := json.Marshal(noauthAgt) + if err != nil { + return "", err; + } + paramMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes) + out := proxy.InvokeDB("noauthAgent", "update", paramMap) + if len(out) == 0 { + return "", errors.New("Cannot update Agent. ") + } + m := member.Member{} + m.Id = json.Number(memberId) + newAgent := agent.NewAgent(desc, m) + newone, err := agent.NewAgentService().SaveAgent(newAgent) + if err!= nil { + return "", err + } + + return newone, nil +} + +func (as *NoAuthAgentService)ReadNoAuthAgent(id string) (string, error){ + mm := make(map[string]string) + mm["id"] = id + out := proxy.InvokeDB("noauthAgent", "find", mm) + + return out, nil +} \ No newline at end of file diff --git a/proxy/noauthagent/agent_service_test.go b/proxy/noauthagent/agent_service_test.go index 006cc69..4490129 100644 --- a/proxy/noauthagent/agent_service_test.go +++ b/proxy/noauthagent/agent_service_test.go @@ -5,6 +5,7 @@ import ( "github.com/google/uuid" "testing" + "encoding/json" ) @@ -22,9 +23,9 @@ func TestCreateUUid(t *testing.T) { func TestCreateNoAuthAgent(t *testing.T) { - na := NewNoAuthAgent("2334278390283", 111, "Snoop") + na := NewNoAuthAgent("233421390283", 111, "Snoop") - na.TempKey = "22222222" + na.TempKey = "1111111" na.AuthStatus = "WAIT" nas := NewNoAuthAgentService() @@ -72,4 +73,18 @@ func TestNoAuthList(t *testing.T) { t.Log(out) -} \ No newline at end of file +} + +func TestRequestAuth(t *testing.T) { + nas := NewNoAuthAgentService() + res, err := nas.ReadNoAuthAgent("1") + + na := NoAuthAgent{} + json.Unmarshal([]byte(res), na) + + newone, err := nas.RequestAuth(na, "1", "test") + if err!= nil { + t.Fatal(err) + } + t.Log(newone) +} From ac7ce714be73ce0c4885affa45f724e5a792688d Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 5 Jun 2017 21:20:08 +0900 Subject: [PATCH 03/10] typo --- proxy/agent/agent_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/agent/agent_service.go b/proxy/agent/agent_service.go index 29b6c20..375b646 100644 --- a/proxy/agent/agent_service.go +++ b/proxy/agent/agent_service.go @@ -17,7 +17,7 @@ type Agent struct { Description string `json:"description,omitempty"` Member member.Member `json:"member,omitempty"` LastPollingDate int64 `json:"description,omitempty"` - Status string `json:"Status,omitempty"` + Status string `json:"status,omitempty"` } func NewAgentService() *AgentService { From 81b454c86c4bc5d5e8e8e9b5f037e260dea882e8 Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 5 Jun 2017 21:26:46 +0900 Subject: [PATCH 04/10] added target service test --- proxy/target/target_service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxy/target/target_service.go b/proxy/target/target_service.go index 3eabc7c..4b0645e 100644 --- a/proxy/target/target_service.go +++ b/proxy/target/target_service.go @@ -33,6 +33,9 @@ func (t *TargetService)GetModel() interface{} { func (t *TargetService)List(tm *Target) string { + + tm.Member.Id = "1" + bytes, err := json.Marshal(tm) if err != nil { From d255ec8c93302c6a52717691f40fa452453c38e4 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 5 Jun 2017 21:44:20 +0900 Subject: [PATCH 05/10] typo --- proxy/agent/agent_service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/agent/agent_service.go b/proxy/agent/agent_service.go index 375b646..184ee0f 100644 --- a/proxy/agent/agent_service.go +++ b/proxy/agent/agent_service.go @@ -16,7 +16,7 @@ type Agent struct { AuthorizedDate int64 `json:"authorizedDate,Number,omitempty"` Description string `json:"description,omitempty"` Member member.Member `json:"member,omitempty"` - LastPollingDate int64 `json:"description,omitempty"` + LastPollingDate int64 `json:"lastPollingDate,omitempty"` Status string `json:"status,omitempty"` } @@ -24,6 +24,8 @@ func NewAgentService() *AgentService { return &AgentService{} } + + func NewAgent(desc string, member member.Member) *Agent { na := &Agent{ From 81ab013e65ce31adc806cd3a0ffb0ba5c66a2244 Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 5 Jun 2017 21:48:08 +0900 Subject: [PATCH 06/10] typo --- proxy/agent/agent_service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/proxy/agent/agent_service.go b/proxy/agent/agent_service.go index 184ee0f..b8a3cb1 100644 --- a/proxy/agent/agent_service.go +++ b/proxy/agent/agent_service.go @@ -68,3 +68,7 @@ func (as *AgentService) getAgentList(memberId string) (string, error) { return out, nil } + +func (as *AgentService) GetModel() (interface{}) { + return &Agent{} +} From b91a18c6f6531ed6420ebe9935c10c53b597926d Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Mon, 5 Jun 2017 21:52:51 +0900 Subject: [PATCH 07/10] typo --- proxy/noauthagent/agent_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/noauthagent/agent_service.go b/proxy/noauthagent/agent_service.go index e782101..57fe562 100644 --- a/proxy/noauthagent/agent_service.go +++ b/proxy/noauthagent/agent_service.go @@ -7,7 +7,7 @@ import ( "encoding/json" "git.loafle.net/overflow/overflow_proxy_service/proxy/member" "git.loafle.net/overflow/overflow_proxy_service/proxy/agent" - "github.com/reactivex/rxgo/errors" + "errors" ) type NoAuthAgentService struct { From f68d1e6900631a2166980911a2c169bf7a99cd5b Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 6 Jun 2017 15:37:11 +0900 Subject: [PATCH 08/10] changed noauth agent service --- proxy/noauthagent/{agent_service.go => noauth_agent_service.go} | 0 .../{agent_service_test.go => noauth_agent_service_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename proxy/noauthagent/{agent_service.go => noauth_agent_service.go} (100%) rename proxy/noauthagent/{agent_service_test.go => noauth_agent_service_test.go} (100%) diff --git a/proxy/noauthagent/agent_service.go b/proxy/noauthagent/noauth_agent_service.go similarity index 100% rename from proxy/noauthagent/agent_service.go rename to proxy/noauthagent/noauth_agent_service.go diff --git a/proxy/noauthagent/agent_service_test.go b/proxy/noauthagent/noauth_agent_service_test.go similarity index 100% rename from proxy/noauthagent/agent_service_test.go rename to proxy/noauthagent/noauth_agent_service_test.go From e91d23aeac144ee37ecbf8c96b39acf577cb93a2 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 6 Jun 2017 19:53:17 +0900 Subject: [PATCH 09/10] changed check auth return value --- proxy/noauthagent/noauth_agent_service.go | 11 +++++++++++ proxy/noauthagent/noauth_agent_service_test.go | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/proxy/noauthagent/noauth_agent_service.go b/proxy/noauthagent/noauth_agent_service.go index 57fe562..6669eba 100644 --- a/proxy/noauthagent/noauth_agent_service.go +++ b/proxy/noauthagent/noauth_agent_service.go @@ -28,6 +28,11 @@ type NoAuthAgent struct { HostName string `json:"hostName,omitempty"` } +const ( + AUTHSTATUS_WAIT = "WAIT" + AUTHSTATUS_ACCEPT = "ACCEPT" + AUTHSTATUS_REFUSE = "REFUSE" +) @@ -75,6 +80,12 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) { out := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap); + nn := NoAuthAgent{} + err = json.Unmarshal([]byte(out), &nn) + + if err != nil { + return "", err + } return out,nil; } diff --git a/proxy/noauthagent/noauth_agent_service_test.go b/proxy/noauthagent/noauth_agent_service_test.go index 4490129..248ed14 100644 --- a/proxy/noauthagent/noauth_agent_service_test.go +++ b/proxy/noauthagent/noauth_agent_service_test.go @@ -88,3 +88,18 @@ func TestRequestAuth(t *testing.T) { } t.Log(newone) } + + +func TestCheckAuth(t *testing.T) { + + + ns := NewNoAuthAgentService() + + str, err := ns.CheckAuth("3398473-90847903874") + if err != nil { + t.Fatal(err) + } + + t.Log(str) + +} \ No newline at end of file From 7806a1eb9668f06c46df1e6a27166d4efa34c2fe Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 6 Jun 2017 20:02:44 +0900 Subject: [PATCH 10/10] changed check auth return value --- proxy/noauthagent/noauth_agent_service.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/proxy/noauthagent/noauth_agent_service.go b/proxy/noauthagent/noauth_agent_service.go index 6669eba..94b9215 100644 --- a/proxy/noauthagent/noauth_agent_service.go +++ b/proxy/noauthagent/noauth_agent_service.go @@ -28,13 +28,6 @@ type NoAuthAgent struct { HostName string `json:"hostName,omitempty"` } -const ( - AUTHSTATUS_WAIT = "WAIT" - AUTHSTATUS_ACCEPT = "ACCEPT" - AUTHSTATUS_REFUSE = "REFUSE" -) - - func NewNoAuthAgent(apikey string, localIp int64, hostName string) *NoAuthAgent {