104 lines
2.0 KiB
Go
104 lines
2.0 KiB
Go
package noauthagent
|
|
|
|
import (
|
|
|
|
"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)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;
|
|
}
|
|
|
|
|
|
func (as *NoAuthAgentService) GetModel() (interface{}) {
|
|
return NewNoAuthAgent("", 0, "")
|
|
}
|