mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: remove apiversion param from session
This commit is contained in:
@@ -100,7 +100,7 @@ func InitBaseAuth(options *common_options.BaseOptions) {
|
||||
}
|
||||
|
||||
func FetchEtcdServiceInfo() (*identity.EndpointDetails, error) {
|
||||
s := auth.GetAdminSession(context.Background(), "", "")
|
||||
s := auth.GetAdminSession(context.Background(), "")
|
||||
return s.GetCommonEtcdEndpoint()
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (res *SEncryptedResource) GetEncryptInfo(
|
||||
userCred mcclient.TokenCredential,
|
||||
) (apis.SEncryptInfo, error) {
|
||||
ret := apis.SEncryptInfo{}
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
secKey, err := identity_modules.Credentials.GetEncryptKey(session, res.EncryptKeyId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "GetEncryptKey")
|
||||
@@ -82,7 +82,7 @@ func (manager *SEncryptedResourceManager) ValidateCreateData(
|
||||
input apis.EncryptedResourceCreateInput,
|
||||
) (apis.EncryptedResourceCreateInput, error) {
|
||||
if input.EncryptKeyId != nil && len(*input.EncryptKeyId) > 0 {
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "v1")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
keyObj, err := identity_modules.Credentials.Get(session, *input.EncryptKeyId, nil)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "Credentials get key")
|
||||
@@ -103,7 +103,7 @@ func (manager *SEncryptedResourceManager) ValidateCreateData(
|
||||
func (res *SEncryptedResource) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data jsonutils.JSONObject, nameHint string) error {
|
||||
if len(res.EncryptKeyId) == 0 && jsonutils.QueryBoolean(data, "encrypt_key_new", false) && !jsonutils.QueryBoolean(data, "dry_run", false) {
|
||||
// create new encrypt key
|
||||
session := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
session := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
now := time.Now()
|
||||
keyName := "key-" + nameHint + "-" + timeutils.ShortDate(now)
|
||||
algName, _ := data.GetString("encrypt_key_alg")
|
||||
@@ -127,7 +127,7 @@ func (manager *SEncryptedResourceManager) FetchCustomizeColumns(
|
||||
) []apis.EncryptedResourceDetails {
|
||||
rets := make([]apis.EncryptedResourceDetails, len(objs))
|
||||
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
encKeyMap := make(map[string]identity_modules.SEncryptKeySecret)
|
||||
for i := range objs {
|
||||
var base *SEncryptedResource
|
||||
|
||||
@@ -123,7 +123,7 @@ func (manager *SRoleCacheManager) FetchRoleFromKeystone(ctx context.Context, idS
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
query.Set("system", jsonutils.JSONTrue)
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
role, err := modules.RolesV3.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -263,7 +263,7 @@ func (manager *SRoleCacheManager) StartWatchRoleInKeystone() error {
|
||||
return nil
|
||||
}
|
||||
ctx := context.Background()
|
||||
s := auth.GetAdminSession(ctx, "", "")
|
||||
s := auth.GetAdminSession(ctx, "")
|
||||
watchMan, err := informer.NewWatchManagerBySession(s)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -231,7 +231,7 @@ func (manager *STenantCacheManager) fetchTenantFromKeystone(ctx context.Context,
|
||||
query := jsonutils.NewDict()
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
tenant, err := modules.Projects.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -286,7 +286,7 @@ func (manager *STenantCacheManager) fetchDomainFromKeystone(ctx context.Context,
|
||||
log.Debugf("fetch empty domain!!!!\n%s", debug.Stack())
|
||||
return nil, fmt.Errorf("Empty idStr")
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
tenant, err := modules.Domains.GetById(s, idStr, nil)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -421,7 +421,7 @@ func (manager *STenantCacheManager) fetchDomainTenantsFromKeystone(ctx context.C
|
||||
return fmt.Errorf("Empty domainId")
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(domainId), "domain_id")
|
||||
params.Add(jsonutils.JSONTrue, "details")
|
||||
|
||||
@@ -69,7 +69,7 @@ func (w *tenantCacheSyncWorker) Dump() string {
|
||||
}
|
||||
|
||||
func syncDomains(ctx context.Context) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
query := jsonutils.NewDict()
|
||||
query.Add(jsonutils.NewInt(1024), "limit")
|
||||
query.Add(jsonutils.NewString(string(rbacutils.ScopeSystem)), "scope")
|
||||
@@ -98,7 +98,7 @@ func syncDomains(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func syncProjects(ctx context.Context) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
query := jsonutils.NewDict()
|
||||
query.Add(jsonutils.NewInt(1024), "limit")
|
||||
query.Add(jsonutils.NewString(string(rbacutils.ScopeSystem)), "scope")
|
||||
|
||||
@@ -125,7 +125,7 @@ func (manager *SUserCacheManager) FetchUserFromKeystone(ctx context.Context, idS
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
query.Set("system", jsonutils.JSONTrue)
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
user, err := modules.UsersV3.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
|
||||
@@ -237,7 +237,7 @@ func (t *eventTask) Dump() string {
|
||||
}
|
||||
|
||||
func (t *eventTask) Run() {
|
||||
s, err := AdminSessionGenerator(context.Background(), "", "")
|
||||
s, err := AdminSessionGenerator(context.Background(), "")
|
||||
if err != nil {
|
||||
log.Errorf("unable to get admin session: %v", err)
|
||||
return
|
||||
@@ -361,7 +361,7 @@ func IntelliNotify(ctx context.Context, recipientId []string, isGroup bool, chan
|
||||
}
|
||||
|
||||
func FetchNotifyAdminRecipients(ctx context.Context, region string, users []string, groups []string) {
|
||||
s, err := AdminSessionGenerator(ctx, region, "v1")
|
||||
s, err := AdminSessionGenerator(ctx, region)
|
||||
if err != nil {
|
||||
log.Errorf("unable to get admin session: %v", err)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func systemNotify(ctx context.Context, priority npk.TNotifyPriority, event strin
|
||||
}
|
||||
|
||||
func notifyAll(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error {
|
||||
s, err := AdminSessionGenerator(ctx, consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(ctx, consts.GetRegion())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func lang(ctx context.Context, contactType npk.TNotifyChannel, reIds []string, c
|
||||
|
||||
func genMsgViaLang(ctx context.Context, p sNotifyParams) ([]npk.SNotifyMessage, error) {
|
||||
reIds := make([]string, 0)
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func (t *notifyTask) Dump() string {
|
||||
}
|
||||
|
||||
func (t *notifyTask) Run() {
|
||||
s, err := AdminSessionGenerator(t.ctx, consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(t.ctx, consts.GetRegion())
|
||||
if err != nil {
|
||||
log.Errorf("fail to get session: %v", err)
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ var (
|
||||
checkTemplates bool
|
||||
)
|
||||
|
||||
type SAdminSessionGenerator func(ctx context.Context, region string, apiVersion string) (*mcclient.ClientSession, error)
|
||||
type SAdminSessionGenerator func(ctx context.Context, region string) (*mcclient.ClientSession, error)
|
||||
type SUserLangFetcher func(uids []string) (map[string]string, error)
|
||||
|
||||
func getAdminSesion(ctx context.Context, region string, apiVersion string) (*mcclient.ClientSession, error) {
|
||||
return auth.GetAdminSession(ctx, region, apiVersion), nil
|
||||
func getAdminSesion(ctx context.Context, region string) (*mcclient.ClientSession, error) {
|
||||
return auth.GetAdminSession(ctx, region), nil
|
||||
}
|
||||
|
||||
func getUserLang(uids []string) (map[string]string, error) {
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func getUserLang(uids []string) (map[string]string, error) {
|
||||
}
|
||||
|
||||
func getRobotLang(robots []string) (map[string]string, error) {
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (s *mcclientServiceConfigSession) Merge(opts interface{}, serviceType strin
|
||||
s.config = jsonutils.Marshal(opts).(*jsonutils.JSONDict)
|
||||
region, _ := s.config.GetString("region")
|
||||
// epType, _ := s.config.GetString("session_endpoint_type")
|
||||
s.session = auth.GetAdminSession(context.Background(), region, "")
|
||||
s.session = auth.GetAdminSession(context.Background(), region)
|
||||
s.serviceId, _ = getServiceIdByType(s.session, serviceType, serviceVersion)
|
||||
if len(s.serviceId) > 0 {
|
||||
serviceConf, err := getServiceConfig(s.session, s.serviceId)
|
||||
|
||||
@@ -400,7 +400,7 @@ func explainPolicy(userCred mcclient.TokenCredential, policyReq jsonutils.JSONOb
|
||||
}
|
||||
|
||||
func fetchPolicyDataByIdOrName(ctx context.Context, id string) (*sPolicyData, error) {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
data, err := identity.Policies.Get(s, id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Policies.Get")
|
||||
|
||||
@@ -81,7 +81,7 @@ func (manager *SInformerSyncManager) StartWatching(resMan informer.IResourceMana
|
||||
func (manager *SInformerSyncManager) startWatcher() error {
|
||||
log.Infof("[%s] Start resource informer watcher for %s", manager.Name(), manager.resourceManager.GetKeyword())
|
||||
ctx := context.Background()
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
informer.NewWatchManagerBySessionBg(s, func(watchMan *informer.SWatchManager) error {
|
||||
if err := watchMan.For(manager.resourceManager).AddEventHandler(ctx, manager); err != nil {
|
||||
return errors.Wrapf(err, "watch resource %s", manager.resourceManager.GetKeyword())
|
||||
|
||||
Reference in New Issue
Block a user