fixed
noauthprobe
This commit is contained in:
parent
74beb66775
commit
34d7a81ae8
@ -3,11 +3,13 @@ package noauthprobe
|
|||||||
import (
|
import (
|
||||||
|
|
||||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/member"
|
"git.loafle.net/overflow/overflow_service/proxy/member"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
||||||
|
"git.loafle.net/overflow/overflow_service/proxy/domain"
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NoAuthProbeService struct {
|
type NoAuthProbeService struct {
|
||||||
@ -20,22 +22,32 @@ func NewNoAuthProbeService() *NoAuthProbeService {
|
|||||||
|
|
||||||
type NoAuthProbe struct {
|
type NoAuthProbe struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
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"`
|
HostName string `json:"hostName,omitempty"`
|
||||||
|
MacAddress int64 `json:"macAddress,omitempty"`
|
||||||
|
IpAddress int64 `json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// P rocess, A ccept, D eny
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
|
||||||
|
TempProbeKey string `json:"tempProbeKey,omitempty"`
|
||||||
|
|
||||||
|
CreateDate timestamp.Timestamp`json:"createDate,omitempty"`
|
||||||
|
ApiKey string `json:"apiKey,omitempty"`
|
||||||
|
Domain domain.Domain `json:"domain,omitempty"`
|
||||||
|
Probe probe.Probe `json:"probe,omitempty"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func NewNoAuthProbe(apikey string, localIp int64, hostName string) *NoAuthProbe {
|
func NewNoAuthProbe(apikey string, ipAddress int64, hostName string, md int64) *NoAuthProbe {
|
||||||
|
|
||||||
na := &NoAuthProbe{
|
na := &NoAuthProbe{
|
||||||
Date:timestamp.Now(),
|
CreateDate:timestamp.Now(),
|
||||||
ApiKey:apikey,
|
ApiKey:apikey,
|
||||||
LocalIP:localIp,
|
IpAddress:ipAddress,
|
||||||
HostName:hostName,
|
HostName:hostName,
|
||||||
|
MacAddress:md,
|
||||||
}
|
}
|
||||||
return na
|
return na
|
||||||
}
|
}
|
||||||
@ -44,15 +56,17 @@ func NewNoAuthProbe(apikey string, localIp int64, hostName string) *NoAuthProbe
|
|||||||
func(as *NoAuthProbeService)Save(na *NoAuthProbe) (string, error) {
|
func(as *NoAuthProbeService)Save(na *NoAuthProbe) (string, error) {
|
||||||
|
|
||||||
|
|
||||||
bytes, err := json.Marshal(na)
|
//bytes, err := json.Marshal(na)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return "",err
|
// return "",err
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
//memMap := make(map[string]string)
|
||||||
|
//memMap["com.loafle.overflow.module.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
||||||
|
//
|
||||||
|
//out, err := proxy.InvokeDB("noauthProbe", "save", memMap);
|
||||||
|
|
||||||
memMap := make(map[string]string)
|
out, err := utils.InvokeDBByModel("noauthProbe", "save", na, "com.loafle.overflow.module.noauthprobe.model.NoAuthProbe")
|
||||||
memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
|
||||||
|
|
||||||
out, err := proxy.InvokeDB("noauthProbe", "create", memMap);
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -63,19 +77,21 @@ func(as *NoAuthProbeService)Save(na *NoAuthProbe) (string, error) {
|
|||||||
|
|
||||||
func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) {
|
func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) {
|
||||||
|
|
||||||
memMap := make(map[string]string)
|
//memMap := make(map[string]string)
|
||||||
|
//
|
||||||
|
//na := NewNoAuthProbe("", 0, "", 0)
|
||||||
|
//na.TempProbeKey = tempKey
|
||||||
|
//
|
||||||
|
//bytes, err := json.Marshal(na)
|
||||||
|
//if err != nil {
|
||||||
|
// return "", err;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
||||||
|
//
|
||||||
|
//out, err := proxy.InvokeDB("noauthProbe", "findByTempKey", memMap);
|
||||||
|
|
||||||
na := NewNoAuthProbe("", 0, "")
|
out, err:= utils.InvokeDBByModel("noauthProbe","findByTempProbeKey",tempKey, "java.lang.String")
|
||||||
na.TempKey = tempKey
|
|
||||||
|
|
||||||
bytes, err := json.Marshal(na)
|
|
||||||
if err != nil {
|
|
||||||
return "", err;
|
|
||||||
}
|
|
||||||
|
|
||||||
memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
|
||||||
|
|
||||||
out, err := proxy.InvokeDB("noauthProbe", "findByTempKey", memMap);
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -92,50 +108,63 @@ func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func(as *NoAuthProbeService)GetList(excludeStatus string) (string,error) {
|
func(as *NoAuthProbeService)GetList(d *domain.Domain) (string,error) {
|
||||||
|
|
||||||
memMap := make(map[string]string)
|
//memMap := make(map[string]string)
|
||||||
|
//
|
||||||
|
//na := NewNoAuthProbe("", 0, "", 0)
|
||||||
|
//na.Status = excludeStatus
|
||||||
|
//
|
||||||
|
//bytes, err := json.Marshal(na)
|
||||||
|
//if err != nil {
|
||||||
|
// return "", err;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
||||||
|
//
|
||||||
|
//out, err := proxy.InvokeDB("noauthProbe", "findAllByNoAuth", memMap);
|
||||||
|
|
||||||
na := NewNoAuthProbe("", 0, "")
|
out, err := utils.InvokeDBByModel("noauthProbe","findAllByDomain", d, "com.loafle.overflow.module.domain.model.Domain");
|
||||||
na.AuthStatus = excludeStatus
|
|
||||||
|
|
||||||
bytes, err := json.Marshal(na)
|
|
||||||
if err != nil {
|
|
||||||
return "", err;
|
|
||||||
}
|
|
||||||
|
|
||||||
memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
|
||||||
|
|
||||||
out, err := proxy.InvokeDB("noauthProbe", "findAllByNoAuth", memMap);
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return out,nil;
|
return out,nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (as *NoAuthProbeService)RequestAuth(noauthAgt NoAuthProbe, memberId, desc string) (string, error) {
|
func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, memberId int, desc string) (string, error) {
|
||||||
paramMap := make(map[string]string)
|
//paramMap := make(map[string]string)
|
||||||
noauthAgt.AuthStatus = "ACCEPT"
|
//noauthAgt.Status = "A"
|
||||||
|
//
|
||||||
|
//bytes, err := json.Marshal(noauthAgt)
|
||||||
|
//if err != nil {
|
||||||
|
// return "", err;
|
||||||
|
//}
|
||||||
|
//paramMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes)
|
||||||
|
//out, err := proxy.InvokeDB("noauthProbe", "update", paramMap)
|
||||||
|
|
||||||
bytes, err := json.Marshal(noauthAgt)
|
out ,err := utils.InvokeDBByModel("noauthProbe","findByTempProbeKey", np.TempProbeKey, "java.lang.String");
|
||||||
if err != nil {
|
|
||||||
return "", err;
|
|
||||||
}
|
|
||||||
paramMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes)
|
|
||||||
out, err := proxy.InvokeDB("noauthProbe", "update", paramMap)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
return "", errors.New("Cannot update Probe. ")
|
return "", errors.New("Cannot update Probe. ")
|
||||||
}
|
}
|
||||||
|
dbnp := NoAuthProbe{}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &dbnp);
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
dbnp.Status = np.Status;
|
||||||
|
|
||||||
|
//FIXME:: probe
|
||||||
|
|
||||||
m := member.Member{}
|
m := member.Member{}
|
||||||
m.Id = json.Number(memberId)
|
m.Id = json.Number(memberId)
|
||||||
newAgent := probe.NewAgent(desc, m)
|
newAgent := probe.NewAgent(desc, m)
|
||||||
@ -148,9 +177,11 @@ func (as *NoAuthProbeService)RequestAuth(noauthAgt NoAuthProbe, memberId, desc s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (as *NoAuthProbeService)Read(id string) (string, error){
|
func (as *NoAuthProbeService)Read(id string) (string, error){
|
||||||
mm := make(map[string]string)
|
//mm := make(map[string]string)
|
||||||
mm["id"] = id
|
//mm["id"] = id
|
||||||
out, err := proxy.InvokeDB("noauthProbe", "find", mm)
|
//out, err := proxy.InvokeDB("noauthProbe", "findOne", id, "java.lang.Long")
|
||||||
|
|
||||||
|
out,err :=utils.InvokeDBByModel("noauthProbe","findOne",id,"java.lang.Long")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"encoding/json"
|
"git.loafle.net/overflow/overflow_service/proxy/domain"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -20,44 +21,44 @@ func TestCreateUUid(t *testing.T) {
|
|||||||
t.Log(uu)
|
t.Log(uu)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
func TestCreateNoAuthAgent(t *testing.T) {
|
//func TestCreateNoAuthAgent(t *testing.T) {
|
||||||
|
//
|
||||||
na := NewNoAuthProbe("233421390283", 111, "Snoop")
|
// na := NewNoAuthProbe("233421390283", 111, "Snoop")
|
||||||
|
//
|
||||||
na.TempKey = "1111111"
|
// na.TempKey = "1111111"
|
||||||
na.AuthStatus = "WAIT"
|
// na.AuthStatus = "WAIT"
|
||||||
|
//
|
||||||
nas := NewNoAuthProbeService()
|
// nas := NewNoAuthProbeService()
|
||||||
|
//
|
||||||
out, err := nas.Save(na)
|
// out, err := nas.Save(na)
|
||||||
|
//
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatal(err)
|
// t.Fatal(err)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
t.Log(out)
|
// t.Log(out)
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func TestCheckAuthNoAuthAgent(t *testing.T) {
|
//func TestCheckAuthNoAuthAgent(t *testing.T) {
|
||||||
|
//
|
||||||
na := NewNoAuthProbe("2334278390283", 111, "Snoop")
|
// na := NewNoAuthProbe("2334278390283", 111, "Snoop")
|
||||||
|
//
|
||||||
na.TempKey = "alsdkjf;alkdjsf;la"
|
// na.TempKey = "alsdkjf;alkdjsf;la"
|
||||||
na.AuthStatus = "WAIT"
|
// na.AuthStatus = "WAIT"
|
||||||
|
//
|
||||||
nas := NewNoAuthProbeService()
|
// nas := NewNoAuthProbeService()
|
||||||
|
//
|
||||||
out, err := nas.CheckAuth(na.TempKey)
|
// out, err := nas.CheckAuth(na.TempKey)
|
||||||
|
//
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatal(err)
|
// t.Fatal(err)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
t.Log(out)
|
// t.Log(out)
|
||||||
//
|
// //
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
func TestNoAuthList(t *testing.T) {
|
func TestNoAuthList(t *testing.T) {
|
||||||
@ -65,7 +66,10 @@ func TestNoAuthList(t *testing.T) {
|
|||||||
|
|
||||||
nas := NewNoAuthProbeService()
|
nas := NewNoAuthProbeService()
|
||||||
|
|
||||||
out, err := nas.GetList("ACCEPT")
|
d := domain.Domain{}
|
||||||
|
d.Id = "1"
|
||||||
|
|
||||||
|
out, err := nas.GetList(&d)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -74,20 +78,20 @@ func TestNoAuthList(t *testing.T) {
|
|||||||
t.Log(out)
|
t.Log(out)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
func TestRequestAuth(t *testing.T) {
|
//func TestRequestAuth(t *testing.T) {
|
||||||
nas := NewNoAuthProbeService()
|
// nas := NewNoAuthProbeService()
|
||||||
res, err := nas.Read("1")
|
// res, err := nas.Read("1")
|
||||||
|
//
|
||||||
na := NoAuthProbe{}
|
// na := NoAuthProbe{}
|
||||||
json.Unmarshal([]byte(res), na)
|
// json.Unmarshal([]byte(res), na)
|
||||||
|
//
|
||||||
newone, err := nas.RequestAuth(na, "1", "test")
|
// newone, err := nas.RequestAuth(na, "1", "test")
|
||||||
if err!= nil {
|
// if err!= nil {
|
||||||
t.Fatal(err)
|
// t.Fatal(err)
|
||||||
}
|
// }
|
||||||
t.Log(newone)
|
// t.Log(newone)
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
func TestCheckAuth(t *testing.T) {
|
func TestCheckAuth(t *testing.T) {
|
||||||
@ -102,4 +106,17 @@ func TestCheckAuth(t *testing.T) {
|
|||||||
|
|
||||||
t.Log(str)
|
t.Log(str)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestRead(t *testing.T) {
|
||||||
|
|
||||||
|
out, err := NewNoAuthProbeService().Read("1")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(out)
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user