160 lines
3.2 KiB
Go
160 lines
3.2 KiB
Go
package noauthprobe
|
|
|
|
import (
|
|
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
"git.loafle.net/overflow/overflow_service/proxy"
|
|
"encoding/json"
|
|
"git.loafle.net/overflow/overflow_service/proxy/member"
|
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
|
"errors"
|
|
)
|
|
|
|
type NoAuthProbeService struct {
|
|
}
|
|
|
|
func NewNoAuthProbeService() *NoAuthProbeService {
|
|
return &NoAuthProbeService{}
|
|
}
|
|
|
|
|
|
type NoAuthProbe 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 NewNoAuthProbe(apikey string, localIp int64, hostName string) *NoAuthProbe {
|
|
|
|
na := &NoAuthProbe{
|
|
Date:timestamp.Now(),
|
|
ApiKey:apikey,
|
|
LocalIP:localIp,
|
|
HostName:hostName,
|
|
}
|
|
return na
|
|
}
|
|
|
|
|
|
func(as *NoAuthProbeService)Save(na *NoAuthProbe) (string, error) {
|
|
|
|
|
|
bytes, err := json.Marshal(na)
|
|
if err != nil {
|
|
return "",err
|
|
}
|
|
|
|
memMap := make(map[string]string)
|
|
memMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes);
|
|
|
|
out, err := proxy.InvokeDB("noauthProbe", "create", memMap);
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil;
|
|
}
|
|
|
|
func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) {
|
|
|
|
memMap := make(map[string]string)
|
|
|
|
na := NewNoAuthProbe("", 0, "")
|
|
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 {
|
|
return "", err
|
|
}
|
|
|
|
nn := NoAuthProbe{}
|
|
err = json.Unmarshal([]byte(out), &nn)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out,nil;
|
|
}
|
|
|
|
|
|
func(as *NoAuthProbeService)GetList(excludeStatus string) (string,error) {
|
|
|
|
memMap := make(map[string]string)
|
|
|
|
na := NewNoAuthProbe("", 0, "")
|
|
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 {
|
|
return "", err
|
|
}
|
|
|
|
|
|
return out,nil;
|
|
}
|
|
|
|
|
|
|
|
func (as *NoAuthProbeService)RequestAuth(noauthAgt NoAuthProbe, 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.noauthprobe.model.NoAuthProbe"] = string(bytes)
|
|
out, err := proxy.InvokeDB("noauthProbe", "update", paramMap)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if len(out) == 0 {
|
|
return "", errors.New("Cannot update Probe. ")
|
|
}
|
|
m := member.Member{}
|
|
m.Id = json.Number(memberId)
|
|
newAgent := probe.NewAgent(desc, m)
|
|
newone, err := probe.NewProbeService().SaveAgent(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", "find", mm)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
} |