Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biz/model/device_ability/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func init() {

deviceAbility.AospaceAppSupport = true
deviceAbility.AospaceDevOptionSupport = true
deviceAbility.AospaceSwitchPlatformSupport = true
deviceAbility.AospaceSwitchPlatformSupport = false
deviceAbility.OpenSource = true
deviceAbility.UpgradeApiSupport = true
}
Expand Down
11 changes: 11 additions & 0 deletions biz/model/dto/bind/identify/ticket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package identify

type TicketRsp struct {
Ticket string `json:"ticket"` // 临时ticket用于通道认证,web携带后可以临时访问平台
ExpiresAt string `json:"expiresAt"` // 过期时间,秒时间戳
}

type TicketReq struct {
BoxUuid string `json:"boxUuid"`
PlatformUrl string `json:"platformUrl"` //平台的url
}
1 change: 1 addition & 0 deletions biz/model/dto/bind/space/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type CreateReq struct {
SpaceName string `json:"spaceName" binding:"required"` // 空间名称
Password string `json:"password" binding:"required"` // 空间密码
EnableInternetAccess bool `json:"enableInternetAccess"` // 是否启用互联网通道
ChannelIdentified bool `json:"channelIdentified"` // 通道是否认证
PlatformApiBase string `json:"platformApiBase"` // Platform api url setting, e.g. "https://ao.space"`
VerifyMethod []*document.VerificationMethod `json:"verificationMethod" binding:"required"` // did 的验证方法
}
Expand Down
6 changes: 3 additions & 3 deletions biz/model/dto/httpbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const (
AgentCodeSwitchTaskNotFoundErr = "AG-580" //切换任务未找到
AgentCodeConnectErr = "AG-581" //连接错误
//AlreadyLatestVersion = "AG-591"

GatewayCodeOkStr = "GW-200"
AccountCodeOkStr = "ACC-200"
AgentGetTicketFailed = "AG-616"
GatewayCodeOkStr = "GW-200"
AccountCodeOkStr = "ACC-200"
)

type BaseRsp struct {
Expand Down
52 changes: 52 additions & 0 deletions biz/model/platform/baseUrl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package platform

type PlatformUrl struct {
AppSSPlatformUrl string
AppPSPlatformUrl string
AppAppstoreAppApiUrl string
AppAppstoreAppSignUrl string
}

var BaseUrlMap map[string]PlatformUrl

func init() {
baseUrlMap := make(map[string]PlatformUrl)
baseUrlMap["CN"] = PlatformUrl{
AppSSPlatformUrl: "https://ao.space",
AppPSPlatformUrl: "https://ao.space",
AppAppstoreAppApiUrl: "https://api.apps.ao.space",
AppAppstoreAppSignUrl: "https://auth.apps.ao.space",
}
baseUrlMap["SG"] = PlatformUrl{
AppSSPlatformUrl: "https://aospace.sg",
AppPSPlatformUrl: "https://aospace.sg",
AppAppstoreAppApiUrl: "https://api.apps.aospace.sg",
AppAppstoreAppSignUrl: "https://auth.apps.aospace.sg",
}
baseUrlMap["dev"] = PlatformUrl{
AppSSPlatformUrl: "https://dev.eulix.xyz",
AppPSPlatformUrl: "https://dev.eulix.xyz",
AppAppstoreAppApiUrl: "https://api.dev-apps.eulix.xyz",
AppAppstoreAppSignUrl: "https://auth.dev-apps.eulix.xyz",
}
baseUrlMap["dev2"] = PlatformUrl{
AppSSPlatformUrl: "https://dev2.eulix.xyz",
AppPSPlatformUrl: "https://dev2.eulix.xyz",
AppAppstoreAppApiUrl: "https://api.dev2-apps.eulix.xyz",
AppAppstoreAppSignUrl: "https://auth.dev2-apps.eulix.xyz",
}
baseUrlMap["sit"] = PlatformUrl{
AppSSPlatformUrl: "https://sit.eulix.xyz",
AppPSPlatformUrl: "https://sit.eulix.xyz",
AppAppstoreAppApiUrl: "https://api.sit-apps.eulix.xyz",
AppAppstoreAppSignUrl: "https://auth.sit-apps.eulix.xyz",
}
baseUrlMap["sit2"] = PlatformUrl{
AppSSPlatformUrl: "https://sit2.eulix.xyz",
AppPSPlatformUrl: "https://sit2.eulix.xyz",
AppAppstoreAppApiUrl: "https://api.sit2-apps.eulix.xyz",
AppAppstoreAppSignUrl: "https://auth.sit2-apps.eulix.xyz",
}

BaseUrlMap = baseUrlMap
}
87 changes: 87 additions & 0 deletions biz/service/bind/identify/ticket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package identify

import (
"agent/biz/model/device"
"agent/biz/model/dto"
"agent/biz/model/dto/bind/identify"
"agent/biz/service/base"
"agent/biz/service/pair"
"agent/config"
"agent/utils/logger"
utilshttp "agent/utils/network/http"
"github.com/dungeonsnd/gocom/encrypt/random"
"net/http"
"time"
)

type TicketService struct {
base.BaseService
}

func (svc *TicketService) Process() dto.BaseRspStr {
req := svc.Req.(*identify.TicketReq)
ticket, err := GetTempTicket(req.PlatformUrl)
if err != nil {
return dto.BaseRspStr{Code: dto.AgentGetTicketFailed, Message: err.Error()}
}

svc.Rsp = ticket

return svc.BaseService.Process()
}

func GetTempTicket(platformUrl string) (*identify.TicketRsp, error) {
//先获取 box-reg-key
if boxRegKeyInfo, err := pair.GetDeviceRegKey("https://" + platformUrl); err != nil {
logger.AppLogger().Warnf("ServiceRegisterBox, failed GetBoxRegKey, err:%+v", err)
return nil, err
} else {
logger.AppLogger().Debugf("ServiceRegisterBox, succ GetBoxRegKey, boxRegKeyInfo:%+v", boxRegKeyInfo)
device.SetDeviceRegKey(boxRegKeyInfo.BoxRegKey, boxRegKeyInfo.ExpiresAt)
}
// 平台请求结构
type registryStruct struct {
BoxUUID string `json:"boxUUID"`
}
// 平台响应结构
type ticketRspStruct struct {
Ticket string `json:"ticket"`
ExpiresAt string `json:"expiresAt"`
}

// 请求平台
parms := &registryStruct{BoxUUID: device.GetDeviceInfo().BoxUuid}
// url := config.Config.Platform.APIBase.Url + config.Config.Platform.RegistryBox.Path
url := "https://" + platformUrl + config.Config.Platform.GetChannelTicket.Path
logger.AppLogger().Debugf("ServiceGetChannelTempTicket, v2, url:%+v, parms:%+v", url, parms)

var headers = map[string]string{"Request-Id": random.GenUUID(), "Box-Reg-Key": device.GetDeviceInfo().BoxRegKey}
var rsp identify.TicketRsp

tryTotal := 3
// var httpReq *http.Request
var httpRsp *http.Response
var body []byte
var err1 error
for i := 0; i < tryTotal; i++ {
_, httpRsp, body, err1 = utilshttp.PostJsonWithHeaders(url, parms, headers, &rsp)
if err1 != nil {
// logger.AppLogger().Warnf("Failed PostJson, err:%v, @@httpReq:%+v, @@httpRsp:%+v, @@body:%v", err1, httpReq, httpRsp, string(body))
if i == tryTotal-1 {
return nil, err1
}
time.Sleep(time.Second * 2)
continue
} else {
break
}
}

logger.AppLogger().Infof("ServiceRegisterBox, parms:%+v", parms)
logger.AppLogger().Infof("ServiceRegisterBox, rsp:%+v", rsp)
// logger.AppLogger().Infof("ServiceRegisterBox, httpReq:%+v", httpReq)
logger.AppLogger().Infof("ServiceRegisterBox, httpRsp:%+v", httpRsp)
logger.AppLogger().Infof("ServiceRegisterBox, body:%v", string(body))

return &rsp, nil
}
59 changes: 36 additions & 23 deletions biz/service/bind/space/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"agent/biz/model/dto"
"agent/biz/model/dto/bind/space/create"
"agent/biz/model/gt"
"agent/biz/model/platform"
"agent/biz/service/base"
"agent/biz/service/call"
"agent/biz/service/pair"
Expand All @@ -32,6 +33,7 @@ import (
"agent/utils/retry"
"encoding/base64"
"fmt"
"strings"
"time"
)

Expand Down Expand Up @@ -63,15 +65,26 @@ func (svc *SpaceCreateService) Process() dto.BaseRspStr {
logger.AppLogger().Debugf("SpaceCreateService, rebind:%+v", svc.PairedInfo.Rebind())

// 注册平台
if req.EnableInternetAccess && !svc.PairedInfo.Rebind() { // 首次且开启互联网通道情况下。解绑后重新绑定时不改变互联网服务配置。
if req.ChannelIdentified && req.EnableInternetAccess && !svc.PairedInfo.Rebind() { // 首次且开启互联网通道情况下。解绑后重新绑定时不改变互联网服务配置。

if req.PlatformApiBase != "" {

device.SetApiBaseUrl(req.PlatformApiBase)
//envFiles := make(map[string]map[string]string)
//gwEnvFile := make(map[string]string)
//gwEnvFile["APP_SSPLATFORM_URL"] = req.PlatformApiBase
//envFiles["aospace-gateway.env"] = gwEnvFile
//docker.ProcessEnv(config.Config.Docker.ComposeFile, envFiles)
envFiles := make(map[string]map[string]string)
gwEnvFile := make(map[string]string)
gwEnvFile["APP_SSPLATFORM_URL"] = req.PlatformApiBase

for _, urls := range platform.BaseUrlMap {
if strings.Contains(urls.AppPSPlatformUrl, req.PlatformApiBase) {
gwEnvFile["APP_APPSTORE_APPAPI_URL"] = urls.AppAppstoreAppApiUrl
gwEnvFile["APP_APPSTORE_APPSIGN_URL"] = urls.AppAppstoreAppSignUrl
gwEnvFile["APP_PSPLATFORM_URL"] = req.PlatformApiBase
}
}

envFiles["aospace-gateway.env"] = gwEnvFile
docker.ProcessEnv(config.Config.Docker.ComposeFile, envFiles)

}

result, err := svc.registerDevice(req)
Expand Down Expand Up @@ -169,23 +182,23 @@ func (svc *SpaceCreateService) callGateway(req *create.CreateReq) (call.MicroSer

// 调用网关接口切换平台

if req.PlatformApiBase != config.Config.Platform.APIBase.Url && req.PlatformApiBase != "" {
type ChangePlatformReq struct {
SSPlatformUrl string `json:"ssplatformUrl"`
}
changePlatformReq := &ChangePlatformReq{SSPlatformUrl: req.PlatformApiBase}
switchPlatformReq := func() error {
err := call.CallServiceByPost(config.Config.GateWay.SwitchPlatform.Url, nil, changePlatformReq, &microServerRsp)
if err != nil {
return err
}
return nil
}
err := retry.Retry(switchPlatformReq, 3, time.Second*2)
if err != nil {
return microServerRsp, err
}
}
//if req.PlatformApiBase != config.Config.Platform.APIBase.Url && req.PlatformApiBase != "" {
// type ChangePlatformReq struct {
// SSPlatformUrl string `json:"ssplatformUrl"`
// }
// changePlatformReq := &ChangePlatformReq{SSPlatformUrl: req.PlatformApiBase}
// switchPlatformReq := func() error {
// err := call.CallServiceByPost(config.Config.GateWay.SwitchPlatform.Url, nil, changePlatformReq, &microServerRsp)
// if err != nil {
// return err
// }
// return nil
// }
// err := retry.Retry(switchPlatformReq, 3, time.Second*2)
// if err != nil {
// return microServerRsp, err
// }
//}
// 调用网关的 "/space/v2/api/space/admin"
type CreateStruct struct {
ClientUUID string `json:"clientUUID,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions biz/service/switch-platform/network_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import (
"agent/biz/docker"
"agent/biz/model/device"
"agent/biz/model/gt"
"agent/biz/model/platform"
"agent/biz/service/network"
"agent/config"
"agent/utils"
"strings"

"agent/utils/logger"
)
Expand Down Expand Up @@ -84,6 +86,13 @@ func networkSwitchV2(newSSP bool) error {

gwEnvFile := make(map[string]string)
gwEnvFile["APP_SSPLATFORM_URL"] = si.NewApiBaseUrl
for _, urls := range platform.BaseUrlMap {
if strings.EqualFold(urls.AppPSPlatformUrl, si.NewApiBaseUrl) {
gwEnvFile["APP_APPSTORE_APPAPI_URL"] = urls.AppAppstoreAppApiUrl
gwEnvFile["APP_APPSTORE_APPSIGN_URL"] = urls.AppAppstoreAppSignUrl
gwEnvFile["APP_PSPLATFORM_URL"] = si.NewApiBaseUrl
}
}
envFiles["aospace-gateway.env"] = gwEnvFile
err := gtConfig.Switch(remoteAPI, clientId, secret)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions biz/web/handler/bind/identify/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package identify

import (
"agent/biz/model/dto/bind/identify"
identifySvc "agent/biz/service/bind/identify"
"agent/config"
"agent/utils/logger"
"github.com/gin-gonic/gin"
"net/http"
)

// GetTicket godoc
// @Summary 获取临时ticket [客户端蓝牙/局域网调用/网关call调用]
// @Description 通道认证,client获取临时ticket
// @ID GetTicket
// @Tags Pair
// @Accept plain
// @Produce json
// @Param ticketReq body identify.TicketReq true "boxuuid"
// @Success 200 {object} dto.BaseRspStr{results=identify.TicketRsp} "code=AG-200 成功;"
// @Router /agent/v1/api/bind/identify/ticket [POST]
func GetTicket(c *gin.Context) {
logger.AppLogger().Debugf("%+v", c.Request)

var req identify.TicketReq
svc := new(identifySvc.TicketService)
if c.Request.Host == config.Config.Web.DockerLocalListenAddr {
c.JSON(http.StatusOK, svc.InitGatewayService("", c.Request.Header, c).Enter(svc, &req))
} else {
c.JSON(http.StatusOK, svc.InitLanService("", c.Request.Header, c).Enter(svc, &req))
}

}
3 changes: 3 additions & 0 deletions biz/web/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"agent/biz/web/handler/bind/bindinit"
"agent/biz/web/handler/bind/com/progress"
"agent/biz/web/handler/bind/com/start"
"agent/biz/web/handler/bind/identify"
internetserviceconfig "agent/biz/web/handler/bind/internet/service/config"
"agent/biz/web/handler/bind/password"
"agent/biz/web/handler/bind/revoke"
Expand Down Expand Up @@ -99,6 +100,7 @@ func ExternalRouter() *gin.Engine {
bind.GET("/internet/service/config", internetserviceconfig.GetConfig)
bind.POST("/password/verify", password.Verify)
bind.POST("/revoke", revoke.Revoke)
bind.POST("/identify/ticket", identify.GetTicket)
}

api.GET("/space/ready/check", space.ReadyCheck)
Expand Down Expand Up @@ -185,6 +187,7 @@ func InternalRouter() *gin.Engine {
{
bindGroup.POST("/internet/service/config", internetserviceconfig.PostConfig)
bindGroup.GET("/internet/service/config", internetserviceconfig.GetConfig)
bindGroup.POST("/identify/ticket", identify.GetTicket)
}

did := v1.Group("/did")
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ var Config = struct {
Path string `default:"/v2/platform/boxes"`
}

GetChannelTicket struct {
Path string `default:"/v2/platform/channel/ticket"`
}
GetDomainTicket struct {
Path string `default:"/v2/platform/channel/user/ticket"`
}
PresetBoxInfo struct {
Path string `default:"/v2/service/trail/boxinfos"`
}
Expand Down
Loading