168 lines
3.7 KiB
Go
168 lines
3.7 KiB
Go
package noauthprobe
|
|
|
|
import (
|
|
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
|
|
"encoding/json"
|
|
|
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
|
"git.loafle.net/overflow/overflow_service/proxy/domain"
|
|
"errors"
|
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
|
)
|
|
|
|
type NoAuthProbeService struct {
|
|
}
|
|
|
|
func NewNoAuthProbeService() *NoAuthProbeService {
|
|
return &NoAuthProbeService{}
|
|
}
|
|
|
|
|
|
type NoAuthProbe struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
|
|
HostName string `json:"hostName,omitempty"`
|
|
MacAddress int64 `json:"macAddress,omitempty"`
|
|
IpAddress int64 `json:"ipAddress,omitempty"`
|
|
|
|
// P rocess, A ccept, D eny
|
|
Status *meta.MetaNoAuthProbeStatus `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, ipAddress int64, hostName string, md int64) *NoAuthProbe {
|
|
|
|
na := &NoAuthProbe{
|
|
CreateDate:timestamp.Now(),
|
|
ApiKey:apikey,
|
|
IpAddress:ipAddress,
|
|
HostName:hostName,
|
|
MacAddress:md,
|
|
Status:meta.NewMetaNoAuthProbeStatus(meta.NOAUTH_PROBE_STATUS_PROCESS),
|
|
}
|
|
return na
|
|
}
|
|
|
|
|
|
func(as *NoAuthProbeService)Regist(na *NoAuthProbe) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel("noauthProbe", "save", na, utils.MODEL_NOAUTHPROBE)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil;
|
|
}
|
|
|
|
func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) {
|
|
|
|
//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);
|
|
|
|
out, err:= utils.InvokeDBByModel("noauthProbe","findByTempProbeKey",tempKey, utils.MODEL_STRING)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
nn := NoAuthProbe{}
|
|
err = json.Unmarshal([]byte(out), &nn)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out,nil;
|
|
}
|
|
|
|
|
|
func(as *NoAuthProbeService)ReadAllByDomain(d *domain.Domain) (string,error) {
|
|
|
|
out, err := utils.InvokeDBByModel("noauthProbe","findAllByDomain", d, utils.MODEL_DOMAIN);
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out,nil;
|
|
}
|
|
|
|
|
|
|
|
func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, domainId int, desc string) (string, error) {
|
|
//paramMap := make(map[string]string)
|
|
//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)
|
|
|
|
out ,err := utils.InvokeDBByModel("noauthProbe","findByTempProbeKey", np.TempProbeKey, utils.MODEL_STRING);
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(out) == 0 {
|
|
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
|
|
|
|
d := domain.Domain{}
|
|
d.Id = json.Number(domainId)
|
|
newAgent := probe.NewProbe("", "")
|
|
newone, err := probe.NewProbeService().Regist(newAgent)
|
|
if err!= nil {
|
|
return "", err
|
|
}
|
|
|
|
return newone, nil
|
|
}
|
|
|
|
func (as *NoAuthProbeService)Read(id string) (string, error){
|
|
//mm := make(map[string]string)
|
|
//mm["id"] = id
|
|
//out, err := proxy.InvokeDB("noauthProbe", "findOne", id, "java.lang.Long")
|
|
|
|
out,err :=utils.InvokeDBByModel("noauthProbe","findOne",id,utils.MODEL_LONG)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
} |