feat: 接入消息加密与实名认证能力
This commit is contained in:
@@ -90,6 +90,7 @@ func initAdminInternalAPI(raw json.RawMessage) (*adminInternalClient, error) {
|
||||
}
|
||||
store.SetAdminInternalConfigProvider(client)
|
||||
loginIPWhitelistProvider = client
|
||||
go store.WarmMessageEncryptionKeys()
|
||||
logs.Info.Printf("Admin internal config client enabled: base_url=%s service=%s", cfg.BaseURL, cfg.ServiceName)
|
||||
return client, nil
|
||||
}
|
||||
@@ -211,6 +212,40 @@ func (c *adminInternalClient) SecurityPolicy(tenantCode string) (*types.Security
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) MessageKey(tenantCode string, version int) (*types.MessageKey, error) {
|
||||
path := "/internal/im-config/tenants/" + url.PathEscape(strings.TrimSpace(tenantCode)) + "/message-keys/active"
|
||||
if version > 0 {
|
||||
path = "/internal/im-config/tenants/" + url.PathEscape(strings.TrimSpace(tenantCode)) + "/message-keys/" + strconv.Itoa(version)
|
||||
}
|
||||
var result types.MessageKey
|
||||
if err := c.getJSON(path, nil, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) MessageKeyAck(tenantCode string, version int) error {
|
||||
if version <= 0 {
|
||||
return types.ErrMalformed
|
||||
}
|
||||
path := "/internal/im-config/tenants/" + url.PathEscape(strings.TrimSpace(tenantCode)) + "/message-keys/ack"
|
||||
return c.doJSON(http.MethodPost, path, nil, map[string]int{"version": version}, nil)
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) RealNamePolicy(id types.TenantID) (*types.RealNamePolicy, error) {
|
||||
if !id.IsValid() {
|
||||
return nil, types.ErrMalformed
|
||||
}
|
||||
var result types.RealNamePolicy
|
||||
path := "/internal/im-config/tenants/by-id/" + strconv.FormatInt(int64(id), 10) + "/realname-policy"
|
||||
if err := c.getJSON(path, nil, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.TenantID = id
|
||||
result.Normalize()
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) TenantLoginIPWhitelist(id types.TenantID) (*tenantLoginIPWhitelistConfig, error) {
|
||||
if !id.IsValid() {
|
||||
return nil, types.ErrMalformed
|
||||
@@ -267,6 +302,10 @@ func (c *adminInternalClient) LatestAppRelease(platform, channel string) (*types
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) getJSON(path string, query url.Values, out any) error {
|
||||
return c.doJSON(http.MethodGet, path, query, nil, out)
|
||||
}
|
||||
|
||||
func (c *adminInternalClient) doJSON(method, path string, query url.Values, payload, out any) error {
|
||||
if c == nil || c.http == nil {
|
||||
return types.ErrUnsupported
|
||||
}
|
||||
@@ -278,11 +317,18 @@ func (c *adminInternalClient) getJSON(path string, query url.Values, out any) er
|
||||
if len(query) > 0 {
|
||||
u.RawQuery = query.Encode()
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
var requestBody []byte
|
||||
if payload != nil {
|
||||
requestBody, err = json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
req, err := http.NewRequest(method, u.String(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.signRequest(req, nil); err != nil {
|
||||
if err = c.signRequest(req, requestBody); err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := c.http.Do(req)
|
||||
|
||||
Reference in New Issue
Block a user