代码拉取完成,页面将自动刷新
package authing_v2
import (
"errors"
"fmt"
"log"
"net/http"
"gitee.com/carlmax_my/console-core-go/pkg/authing/authing_model"
"github.com/Authing/authing-go-sdk/lib/model"
jsoniter "github.com/json-iterator/go"
)
func ConvertTenantModel(m *model.Tenant) *authing_model.Tenant {
return &authing_model.Tenant{
ID: m.ID,
Name: m.Name,
UserPoolID: m.UserPoolID,
}
}
func ConvertTenantDetailModel(m *model.TenantDetails) *authing_model.TenantDetails {
var apps []authing_model.TenantApp
if len(m.Apps) > 0 {
for _, v := range m.Apps {
apps = append(apps, authing_model.TenantApp{
ID: v.ID,
Name: v.Name,
Secret: v.Secret,
})
}
}
return &authing_model.TenantDetails{
Tenant: authing_model.Tenant{
ID: m.ID,
Name: m.Name,
UserPoolID: m.UserPoolID,
},
Apps: apps,
}
}
// 获取用户池下租户列表
func (a *AuthingCli) GetTenantList() (list *[]authing_model.Tenant) {
var tenantList []authing_model.Tenant
resp, _err := a.Cli.GetTenantList(&model.CommonPageRequest{
Page: 1,
Limit: -1,
})
if _err != nil {
log.Println("GetTenantList err:" + _err.Error())
return
}
for _, tenant := range resp.List {
m := ConvertTenantModel(&tenant)
tenantList = append(tenantList, *m)
}
return &tenantList
}
func (a *AuthingCli) GetAppTenantList() (list *[]authing_model.TenantDetails, err error) {
var tenantList []authing_model.TenantDetails
resp, _err := a.Cli.GetTenantList(&model.CommonPageRequest{
Page: 1,
Limit: -1,
})
if _err != nil {
log.Println("GetTenantList err:" + _err.Error())
return nil, err
}
for _, tenant := range resp.List {
if tenantDetail, _err := a.Cli.GetTenantDetails(tenant.ID); _err == nil {
for _, app := range tenantDetail.Apps {
if app.ID == a.AuthCli.AppId {
// log.Println(tenant.ID)
m := ConvertTenantDetailModel(tenantDetail)
tenantList = append(tenantList, *m)
}
}
}
}
return &tenantList, nil
}
func (a *AuthingCli) AddTenantMembers(tenantId, userId *string) error {
_, err := a.Cli.AddTenantMembers(*tenantId, []string{*userId})
return err
}
func (a *AuthingCli) CreateTenant(tenantInfo *authing_model.CreateTenantRequest) (*authing_model.TenantDetails, error) {
req := &model.CreateTenantRequest{
Name: tenantInfo.Name,
AppIds: tenantInfo.AppIds,
Description: tenantInfo.Description,
Logo: tenantInfo.Logo,
}
resp, err := a.Cli.CreateTenant(req)
if err != nil {
return nil, err
}
return &authing_model.TenantDetails{
Tenant: authing_model.Tenant{
ID: resp.ID,
UserPoolID: resp.UserPoolID,
Name: resp.Name,
},
Apps: nil,
}, nil
}
func (a *AuthingCli) UpdateTenant(id *string, tenantInfo *authing_model.CreateTenantRequest) (bool, error) {
req := &model.CreateTenantRequest{
Name: tenantInfo.Name,
AppIds: tenantInfo.AppIds,
Description: tenantInfo.Description,
Logo: tenantInfo.Logo,
}
return a.Cli.UpdateTenant(*id, req)
}
func (a *AuthingCli) UpdateTenant_ExtraInfo(tenantId string, request *authing_model.UpdateTenantExtraReq) (bool, error) {
c := a.Cli
data, _ := jsoniter.Marshal(request)
variables := make(map[string]interface{})
jsoniter.Unmarshal(data, &variables)
url := fmt.Sprintf("%s/api/v2/tenant/%s", c.Host, tenantId)
b, err := c.SendHttpRestRequest(url, http.MethodPost, variables)
if err != nil {
return false, err
}
resp := &struct {
Message string `json:"message"`
Code int64 `json:"code"`
Data bool `json:"data"`
}{}
jsoniter.Unmarshal(b, &resp)
if resp.Code != 200 {
return false, errors.New(resp.Message)
}
return true, nil
}
func (a *AuthingCli) RemoveTenant(tenantId *string) (*string, error) {
return a.Cli.RemoveTenant(*tenantId)
}
func (a *AuthingCli) GetTenantMembers(tenantId *string, userMap map[string]bool, tenantUserMap map[string][]string) (list *[]model.User) {
var userList []model.User
resp, _err := a.Cli.GetTenantMembers(*tenantId, &model.CommonPageRequest{
Page: 1,
Limit: -1,
})
if _err != nil {
log.Println("GetTenantMembers err:" + _err.Error())
return
}
if _, ok := tenantUserMap[*tenantId]; !ok {
tenantUserMap[*tenantId] = make([]string, 0)
}
for _, usr := range resp.List {
uid := usr.User.Id
tid := usr.TenantID
if tid != *tenantId {
continue
}
tenantUserMap[tid] = append(tenantUserMap[tid], uid)
if _, ok := userMap[uid]; !ok {
userList = append(userList, *usr.User)
userMap[uid] = true
}
}
return &userList
}
func (a *AuthingCli) UpdateTenant_loginPage(tenantId string, loginCfg *authing_model.MyAuthingLoginConfig) error {
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。