Ver código fonte

fix: app name管理接口9个

gaoyagang 1 ano atrás
pai
commit
8bfc0bc87c

+ 149 - 0
datacenter_client/types.go

@@ -2,6 +2,21 @@ package datacenter_client
 
 type (
 	// 公共部分
+	Pagination struct {
+		Current  uint32 `json:"current"`
+		PageSize uint32 `json:"pageSize"`
+		Total    uint32 `json:"total"`
+	}
+
+	AppInfo struct {
+		Id         int64   `json:"id"`
+		AppName    string  `json:"app_name"`
+		ProjectIds []int64 `json:"project_ids"`
+		Secret     string  `json:"secret"`
+		Status     int64   `json:"status"`
+		ExpireAt   string  `json:"expire_at"`
+		CTime      string  `json:"c_time"`
+	}
 
 	ItemHistoryResp struct {
 		ProjectId int     `json:"project_id"`
@@ -205,6 +220,57 @@ type (
 		MaxVal     float64 `json:"max_val"`
 		MinVal     float64 `json:"min_val"`
 	}
+
+	FindAppListReq struct {
+		ProjectId int64  `json:"project_id"`
+		Page      int64  `json:"page"`
+		PageSize  int64  `json:"page_size"`
+		Order     string `json:"order"`
+	}
+
+	GetAppInfoReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+	}
+
+	CreateAppInfoReq struct {
+		ProjectId  int64   `json:"project_id"`
+		AppName    string  `json:"app_name"`
+		ProjectIds []int64 `json:"project_ids"`
+		Expire     int64   `json:"expire"`
+	}
+
+	RemoveAppInfoReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+	}
+
+	DisableAppInfoReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+	}
+
+	EnableAppInfoReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+	}
+
+	ResetAppSecretReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+	}
+
+	ExpireAppSecretReq struct {
+		ProjectId int64  `json:"project_id"`
+		AppName   string `json:"app_name"`
+		Expire    int64  `json:"expire"`
+	}
+
+	ResetAppProjectReq struct {
+		ProjectId  int64   `json:"project_id"`
+		AppName    string  `json:"app_name"`
+		ProjectIds []int64 `json:"project_ids"`
+	}
 )
 
 type (
@@ -291,6 +357,79 @@ type (
 		Msg  string                  `json:"msg"`
 		Data ItemHistoryListRespList `json:"data"`
 	}
+
+	FindAppListResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			List       []*AppInfo  `json:"list"`
+			Pagination *Pagination `json:"pagination"`
+		} `json:"data"`
+	}
+
+	GetAppInfoResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			AppInfo *AppInfo `json:"app_info"`
+		} `json:"data"`
+	}
+
+	CreateAppInfoResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			AppInfo *AppInfo `json:"app_info"`
+		} `json:"data"`
+	}
+
+	RemoveAppInfoResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			Ok bool `json:"ok"`
+		} `json:"data"`
+	}
+
+	DisableAppInfoResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			Ok bool `json:"ok"`
+		} `json:"data"`
+	}
+
+	EnableAppInfoResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			Ok bool `json:"ok"`
+		} `json:"data"`
+	}
+
+	ResetAppSecretResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			Secret string `json:"secret"`
+		} `json:"data"`
+	}
+
+	ExpireAppSecretResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			ExpireAt string `json:"expire_at"`
+		} `json:"data"`
+	}
+
+	ResetAppProjectResp struct {
+		Code int    `json:"code"`
+		Msg  string `json:"msg"`
+		Data struct {
+			RemoveProjectIds []int64 `json:"remove_project_ids"`
+		} `json:"data"`
+	}
 )
 
 type (
@@ -319,5 +458,15 @@ type (
 		GetWorkingPumpByCode(DcWorkingReq) (*GetWorkingPumpByCodeResp, error)
 		// 平替双胞胎图表接口(时间区间内按要求聚合)
 		GetItemHistoryList(ItemHistoryListReq) (resp []ItemHistoryListResp, err error)
+
+		FindAppList(FindAppListReq) (*FindAppListResp, error)
+		GetAppInfo(GetAppInfoReq) (*GetAppInfoResp, error)
+		CreateAppInfo(CreateAppInfoReq) (*CreateAppInfoResp, error)
+		RemoveAppInfo(RemoveAppInfoReq) (*RemoveAppInfoResp, error)
+		DisableAppInfo(DisableAppInfoReq) (*DisableAppInfoResp, error)
+		EnableAppInfo(EnableAppInfoReq) (*EnableAppInfoResp, error)
+		ResetAppSecret(ResetAppSecretReq) (*ResetAppSecretResp, error)
+		ExpireAppSecret(ExpireAppSecretReq) (*ExpireAppSecretResp, error)
+		ResetAppProject(ResetAppProjectReq) (*ResetAppProjectResp, error)
 	}
 )

+ 29 - 0
datacenter_client/v1/CreateAppInfo.go

@@ -0,0 +1,29 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) CreateAppInfo(params datacenter_client.CreateAppInfoReq) (*datacenter_client.CreateAppInfoResp, error) {
+	serviceName := "/app/create"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.CreateAppInfoResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+
+	return resp, err
+}

+ 101 - 0
datacenter_client/v1/CreateAppInfo_test.go

@@ -0,0 +1,101 @@
+package v1
+
+import (
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"testing"
+)
+
+var d = NewDcApi(ClientOptions{
+	HTTPSettings: httplib.HTTPSettings{},
+	ServerIp:     "47.96.12.136:8788",
+	AppName:      "add-test1",
+	AppSecret:    "7395fb0cfasyvasd705a2db44a19851a3dbd77f",
+})
+
+func TestDcApi_CreateAppInfo(t *testing.T) {
+	got, err := d.CreateAppInfo(datacenter_client.CreateAppInfoReq{
+		ProjectId:  0,
+		AppName:    "add-test1",
+		ProjectIds: []int64{92, 46, 1187},
+		Expire:     30 * 86400,
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_FindList(t *testing.T) {
+	got, err := d.FindAppList(datacenter_client.FindAppListReq{
+		ProjectId: 0,
+		Page:      1,
+		PageSize:  10,
+		Order:     "id desc",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_GetAppInfo(t *testing.T) {
+	got, err := d.GetAppInfo(datacenter_client.GetAppInfoReq{
+		ProjectId: 0,
+		AppName:   "add-test1",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_EnableAppInfo(t *testing.T) {
+	got, err := d.EnableAppInfo(datacenter_client.EnableAppInfoReq{
+		ProjectId: 0,
+		AppName:   "add-test1",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_DisableAppInfo(t *testing.T) {
+	got, err := d.DisableAppInfo(datacenter_client.DisableAppInfoReq{
+		ProjectId: 0,
+		AppName:   "add-test",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_ResetAppProject(t *testing.T) {
+	got, err := d.ResetAppProject(datacenter_client.ResetAppProjectReq{
+		ProjectId:  0,
+		AppName:    "add-test",
+		ProjectIds: []int64{1, 3, 5, 7, 9},
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_ExpireAppSecret(t *testing.T) {
+	got, err := d.ExpireAppSecret(datacenter_client.ExpireAppSecretReq{
+		ProjectId: 0,
+		AppName:   "add-test",
+		Expire:    86400 * 30,
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_ResetAppSecret(t *testing.T) {
+	got, err := d.ResetAppSecret(datacenter_client.ResetAppSecretReq{
+		ProjectId: 0,
+		AppName:   "add-test",
+	})
+
+	t.Log(got, err)
+}
+
+func TestDcApi_RemoveAppInfo(t *testing.T) {
+	got, err := d.RemoveAppInfo(datacenter_client.RemoveAppInfoReq{
+		ProjectId: 0,
+		AppName:   "add-test",
+	})
+
+	t.Log(got, err)
+}

+ 29 - 0
datacenter_client/v1/DisableAppInfo.go

@@ -0,0 +1,29 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) DisableAppInfo(params datacenter_client.DisableAppInfoReq) (*datacenter_client.DisableAppInfoResp, error) {
+	serviceName := "/app/disable"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.DisableAppInfoResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+
+	return resp, err
+}

+ 27 - 0
datacenter_client/v1/EnableAppInfo.go

@@ -0,0 +1,27 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) EnableAppInfo(params datacenter_client.EnableAppInfoReq) (*datacenter_client.EnableAppInfoResp, error) {
+	serviceName := "/app/enable"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.EnableAppInfoResp{}
+
+	err = d.call(h, resp)
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}

+ 28 - 0
datacenter_client/v1/ExpireAppSecret.go

@@ -0,0 +1,28 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) ExpireAppSecret(params datacenter_client.ExpireAppSecretReq) (*datacenter_client.ExpireAppSecretResp, error) {
+	serviceName := "/app/secret/expire"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.ExpireAppSecretResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}

+ 27 - 0
datacenter_client/v1/FindAppList.go

@@ -0,0 +1,27 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) FindAppList(params datacenter_client.FindAppListReq) (*datacenter_client.FindAppListResp, error) {
+	serviceName := "/app/list"
+	h := httplib.Get(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("page", strconv.FormatInt(params.Page, 10))
+	h.Param("page_size", strconv.FormatInt(params.PageSize, 10))
+	h.Param("order", params.Order)
+
+	resp := &datacenter_client.FindAppListResp{}
+
+	err := d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+
+	return resp, err
+}

+ 24 - 0
datacenter_client/v1/GetAppInfo.go

@@ -0,0 +1,24 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) GetAppInfo(params datacenter_client.GetAppInfoReq) (*datacenter_client.GetAppInfoResp, error) {
+	serviceName := "/app/info"
+	h := httplib.Get(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+	h.Param("app_name", params.AppName)
+
+	resp := &datacenter_client.GetAppInfoResp{}
+
+	err := d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}

+ 28 - 0
datacenter_client/v1/RemoveAppInfo.go

@@ -0,0 +1,28 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) RemoveAppInfo(params datacenter_client.RemoveAppInfoReq) (*datacenter_client.RemoveAppInfoResp, error) {
+	serviceName := "/app/remove"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.RemoveAppInfoResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}

+ 28 - 0
datacenter_client/v1/ResetAppProject.go

@@ -0,0 +1,28 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) ResetAppProject(params datacenter_client.ResetAppProjectReq) (*datacenter_client.ResetAppProjectResp, error) {
+	serviceName := "/app/project/reset"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.ResetAppProjectResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}

+ 28 - 0
datacenter_client/v1/ResetAppSecret.go

@@ -0,0 +1,28 @@
+package v1
+
+import (
+	"errors"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/datacenter_client"
+	"metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
+	"strconv"
+)
+
+func (d *DcApi) ResetAppSecret(params datacenter_client.ResetAppSecretReq) (*datacenter_client.ResetAppSecretResp, error) {
+	serviceName := "/app/secret/reset"
+	h := httplib.Post(d.serviceUrl(serviceName))
+	h.Param("project_id", strconv.FormatInt(params.ProjectId, 10))
+
+	_, err := h.JSONBody(params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp := &datacenter_client.ResetAppSecretResp{}
+
+	err = d.call(h, resp)
+
+	if resp.Code != 200 {
+		return nil, errors.New(resp.Msg)
+	}
+	return resp, err
+}