added
auth
This commit is contained in:
parent
bdc1466270
commit
1d838d813d
|
@ -3,20 +3,92 @@ package initialize
|
|||
import (
|
||||
pb "git.loafle.net/overflow/central_api_gateway/initialize"
|
||||
"context"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/apikey"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/keystore"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/noauthagent"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
|
||||
type InitializeServerImpl struct {
|
||||
}
|
||||
|
||||
func (s *InitializeServerImpl) GetSecretKey(c context.Context, in *pb.AgentInfo) (*pb.InitResponse, error) {
|
||||
|
||||
func (s *InitializeServerImpl) StartAgent(c context.Context, info *pb.AgentInfo) (*pb.InitResponse, error) {
|
||||
output := &pb.InitResponse{}
|
||||
|
||||
//todo. generating secretkey
|
||||
agentId := in.GetAgentId()
|
||||
agentId := info.GetAgentId()
|
||||
output.SecretKey = "overflow" + agentId
|
||||
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (s *InitializeServerImpl) RequestTempKey(c context.Context, info *pb.ReqTempKeyInfo) (*pb.TempKeyInfo, error) {
|
||||
|
||||
as := apikey.NewApiKeyService()
|
||||
|
||||
ti := &pb.TempKeyInfo{}
|
||||
|
||||
b, err := as.CheckApikey(info.ApiKey)
|
||||
if err != nil {
|
||||
return ti, err
|
||||
}
|
||||
|
||||
if b {
|
||||
ks := keystore.NewKeyStoreSerivce()
|
||||
key, err := ks.CreateKey()
|
||||
|
||||
if err != nil {
|
||||
return ti, err
|
||||
}
|
||||
|
||||
ns := noauthagent.NewNoAuthAgentService()
|
||||
_, err = ns.SaveNoAuthAgent(noauthagent.NewNoAuthAgent(info.ApiKey, info.LocalIp, info.HostName))
|
||||
if err != nil {
|
||||
return ti, err
|
||||
}
|
||||
|
||||
ti.TempKey = key
|
||||
//FIXME:: check Poll intervar
|
||||
//ti.PollInterval
|
||||
|
||||
return ti, nil
|
||||
}
|
||||
|
||||
return ti, nil
|
||||
}
|
||||
|
||||
func (s *InitializeServerImpl) CheckAuth(c context.Context, info *pb.TempKey) (*pb.AuthStatus, error) {
|
||||
|
||||
ns := noauthagent.NewNoAuthAgentService()
|
||||
|
||||
as := &pb.AuthStatus{}
|
||||
|
||||
as.Type = pb.AuthStatus_AUTH_WAIT
|
||||
|
||||
str, err := ns.CheckAuth(info.Value)
|
||||
|
||||
if err != nil {
|
||||
return as, err
|
||||
}
|
||||
|
||||
//FIXME auth type
|
||||
res := ""
|
||||
|
||||
err = json.Unmarshal([]byte(str), &res)
|
||||
if err != nil {
|
||||
return as , nil
|
||||
}
|
||||
|
||||
if res == "ACCEPT" {
|
||||
as.Type = pb.AuthStatus_AUTH_ACCEPT
|
||||
} else if res == "REFUSE" {
|
||||
as.Type = pb.AuthStatus_AUTH_REFUSE
|
||||
}
|
||||
|
||||
return as, nil
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user