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:
@@ -151,7 +151,7 @@ func (h *AuthHandlers) GetRegionsResponse(ctx context.Context, w http.ResponseWr
|
||||
EncryptPasswd: true,
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, regions[0], "")
|
||||
s := auth.GetAdminSession(ctx, regions[0])
|
||||
if options.Options.ReturnFullDomainList {
|
||||
filters := jsonutils.NewDict()
|
||||
if len(currentDomain) > 0 {
|
||||
@@ -228,7 +228,7 @@ func (h *AuthHandlers) getUser(ctx context.Context, w http.ResponseWriter, req *
|
||||
|
||||
func getStatsInfo(ctx context.Context, req *http.Request) (jsonutils.JSONObject, error) {
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
params, _ := jsonutils.ParseQueryString(req.URL.RawQuery)
|
||||
|
||||
if params == nil {
|
||||
@@ -306,7 +306,7 @@ func doTenantLogin(ctx context.Context, req *http.Request, body jsonutils.JSONOb
|
||||
}
|
||||
|
||||
func fetchUserInfoFromToken(ctx context.Context, req *http.Request, token mcclient.TokenCredential) (jsonutils.JSONObject, error) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
return fetchUserInfoById(s, token.GetUserId())
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ func (h *AuthHandlers) doCredentialLogin(ctx context.Context, req *http.Request,
|
||||
}
|
||||
uname := token.GetUserName()
|
||||
if len(tenant) > 0 {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
jsonProj, e := modules.Projects.GetById(s, tenant, nil)
|
||||
if e != nil {
|
||||
log.Errorf("fail to find preset project %s, reset to empty", tenant)
|
||||
@@ -430,7 +430,7 @@ func (h *AuthHandlers) doCredentialLogin(ctx context.Context, req *http.Request,
|
||||
}
|
||||
}
|
||||
if len(tenant) == 0 {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
projects, e := modules.UsersV3.GetProjects(s, token.GetUserId())
|
||||
if e == nil && len(projects.Data) > 0 {
|
||||
projectJson := projects.Data[0]
|
||||
@@ -584,7 +584,7 @@ func (h *AuthHandlers) doLogin(ctx context.Context, w http.ResponseWriter, req *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
isTotpInit, err := isUserTotpCredInitialed(s, token.GetUserId())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -844,7 +844,7 @@ func isHostAgentExists(s *mcclient.ClientSession) (bool, error) {
|
||||
|
||||
func getUserInfo(ctx context.Context, req *http.Request) (*jsonutils.JSONDict, error) {
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
/*log.Infof("getUserInfo modules.UsersV3.Get")
|
||||
usr, err := modules.UsersV3.Get(s, token.GetUserId(), nil)
|
||||
if err != nil {
|
||||
@@ -1117,7 +1117,7 @@ func (h *AuthHandlers) doCreatePolicies(ctx context.Context, w http.ResponseWrit
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
result, err := policytool.PolicyCreate(s, body)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -1137,7 +1137,7 @@ func (h *AuthHandlers) doPatchPolicy(ctx context.Context, w http.ResponseWriter,
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
result, err := policytool.PolicyPatch(s, params["<policy_id>"], body)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -1153,7 +1153,7 @@ func (h *AuthHandlers) doDeletePolicies(ctx context.Context, w http.ResponseWrit
|
||||
// return
|
||||
// }
|
||||
_, query, _ := appsrv.FetchEnv(ctx, w, req)
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
|
||||
idlist, e := query.GetArray("id")
|
||||
if e != nil || len(idlist) == 0 {
|
||||
@@ -1245,7 +1245,7 @@ func (h *AuthHandlers) resetUserPassword(ctx context.Context, w http.ResponseWri
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
// 2.如果已开启MFA,验证 随机密码正确
|
||||
if isMfaEnabled(user) {
|
||||
err = authToken.VerifyTotpPasscode(s, t.GetUserId(), input.Passcode)
|
||||
|
||||
@@ -214,7 +214,7 @@ func initTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
code, err := doCreateUserTotpCred(s, t)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -237,7 +237,7 @@ func validatePasscodeHandler(ctx context.Context, w http.ResponseWriter, req *ht
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
@@ -276,7 +276,7 @@ func resetTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
@@ -314,7 +314,7 @@ func listTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req *
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
// 做缓存?
|
||||
ss, err := modules.Credentials.GetRecoverySecrets(s, t.GetUserId())
|
||||
if len(ss) == 0 {
|
||||
@@ -340,7 +340,7 @@ func resetTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
|
||||
@@ -68,8 +68,8 @@ func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFac
|
||||
return "", httperrors.NewBadRequestError("no service")
|
||||
}
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r), "")
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r))
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType, "")
|
||||
if err != nil {
|
||||
return "", httperrors.NewBadRequestError("invalid service %s: %s", serviceName, err)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *CSRFResourceHandler) Bind(app *appsrv.Application) {
|
||||
h.SHandlers.Bind(app)
|
||||
}
|
||||
|
||||
func getAdminSession(ctx context.Context, apiVer string, region string, w http.ResponseWriter) *mcclient.ClientSession {
|
||||
func getAdminSession(ctx context.Context, region string, w http.ResponseWriter) *mcclient.ClientSession {
|
||||
adminToken := auth.AdminCredential()
|
||||
if adminToken == nil {
|
||||
httperrors.NotFoundError(ctx, w, "get admin credential is nil")
|
||||
@@ -60,7 +60,7 @@ func getAdminSession(ctx context.Context, apiVer string, region string, w http.R
|
||||
if !ret {
|
||||
httperrors.NotFoundError(ctx, w, "illegal region %s, please contact admin", region)
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, region, apiVer)
|
||||
s := auth.GetAdminSession(ctx, region)
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func fetchEnvCsrf0(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
log.Infof("csrf region from url: %s", region)
|
||||
session := getAdminSession(ctx, params[APIVer], region, w)
|
||||
session := getAdminSession(ctx, region, w)
|
||||
log.Infof("csrf got session: %s", region)
|
||||
if session == nil {
|
||||
return nil, nil, nil, nil
|
||||
|
||||
@@ -49,7 +49,7 @@ func getSsoBaseCallbackUrl() string {
|
||||
|
||||
func getSsoCallbackUrl(ctx context.Context, req *http.Request, idpId string) string {
|
||||
baseUrl := getSsoBaseCallbackUrl()
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.GetIdpSsoCallbackUriInput{
|
||||
RedirectUri: baseUrl,
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func (h *AuthHandlers) getIdpSsoRedirectUri(ctx context.Context, w http.Response
|
||||
query.(*jsonutils.JSONDict).Set("idp_nonce", jsonutils.NewString(utils.GenRequestId(4)))
|
||||
state := base64.URLEncoding.EncodeToString([]byte(query.String()))
|
||||
redirectUri := getSsoCallbackUrl(ctx, req, idpId)
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.GetIdpSsoRedirectUriInput{
|
||||
RedirectUri: redirectUri,
|
||||
State: state,
|
||||
@@ -145,7 +145,7 @@ func findExtUserId(input string) string {
|
||||
func (h *AuthHandlers) handleIdpInitSsoLogin(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
params := appctx.AppContextParams(ctx)
|
||||
idpId := params["<idp_id>"]
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
resp, err := modules.IdentityProviders.Get(s, idpId, nil)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -383,7 +383,7 @@ func linkWithExistingUser(ctx context.Context, req *http.Request, idpId, idpLink
|
||||
IdpId: idpId,
|
||||
IdpEntityId: extUserId,
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, err = modules.UsersV3.PerformAction(s, t.GetUserId(), "link-idp", jsonutils.Marshal(linkInput))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "link-idp")
|
||||
@@ -413,7 +413,7 @@ func handleUnlinkIdp(ctx context.Context, w http.ResponseWriter, req *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.UserUnlinkIdpInput{
|
||||
IdpId: idpId,
|
||||
IdpEntityId: idpEntityId,
|
||||
@@ -438,7 +438,7 @@ func fetchIdpBasicConfig(ctx context.Context, w http.ResponseWriter, req *http.R
|
||||
}
|
||||
|
||||
func getIdpBasicConfig(ctx context.Context, req *http.Request, idpId string) (jsonutils.JSONObject, error) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
baseUrl := getSsoBaseCallbackUrl()
|
||||
input := api.GetIdpSsoCallbackUriInput{
|
||||
RedirectUri: baseUrl,
|
||||
@@ -468,7 +468,7 @@ func getIdpBasicConfig(ctx context.Context, req *http.Request, idpId string) (js
|
||||
}
|
||||
|
||||
func fetchIdpSAMLMetadata(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
params := appctx.AppContextParams(ctx)
|
||||
idpId := params["<idp_id>"]
|
||||
query := jsonutils.NewDict()
|
||||
|
||||
@@ -130,7 +130,7 @@ func imageUploadHandler(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
|
||||
res, e := modules.Images.Upload(s, params, f, imageSize)
|
||||
if e != nil {
|
||||
@@ -213,7 +213,7 @@ func imageDownload(ctx context.Context, w http.ResponseWriter, s *mcclient.Clien
|
||||
func imageDownloadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
params, query, _ := appsrv.FetchEnv(ctx, w, r)
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
// input params
|
||||
imageId, ok := params["<image_id>"]
|
||||
if !ok || len(imageId) == 0 {
|
||||
@@ -273,7 +273,7 @@ func imageDownloadByUrlHandler(ctx context.Context, w http.ResponseWriter, r *ht
|
||||
return
|
||||
}
|
||||
format, _ := d.GetString("format")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
imageDownload(ctx, w, s, id, format)
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func (h *K8sResourceHandler) fetchEnv(ctx context.Context, req *http.Request) (*
|
||||
namespace, _ := params.GetString("namespace")
|
||||
cluster, _ := params.GetString("cluster")
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
return &k8sResourceEnv{
|
||||
session: s,
|
||||
cluster: cluster,
|
||||
|
||||
@@ -70,9 +70,9 @@ var (
|
||||
BatchHostPXERegisterTemplate = []string{HOST_NAME, HOST_IPMI_ADDR, HOST_IPMI_USERNAME, HOST_IPMI_PASSWORD, HOST_MNG_MAC_ADDR_OPTIONAL, HOST_MNG_IP_ADDR_OPTIONAL}
|
||||
)
|
||||
|
||||
func FetchSession(ctx context.Context, r *http.Request, apiVersion string) *mcclient.ClientSession {
|
||||
func FetchSession(ctx context.Context, r *http.Request) *mcclient.ClientSession {
|
||||
token := AppContextToken(ctx)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r), apiVersion)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
return session
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
s := FetchSession(ctx, req, "")
|
||||
s := FetchSession(ctx, req)
|
||||
params.Set("hosts", jsonutils.NewString(hosts.String()))
|
||||
|
||||
// extra params
|
||||
@@ -301,8 +301,8 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
adminS := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := FetchSession(ctx, req, "")
|
||||
adminS := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
s := FetchSession(ctx, req)
|
||||
files := req.MultipartForm.File
|
||||
|
||||
userfiles, ok := files["users"]
|
||||
@@ -543,7 +543,7 @@ func (mh *MiscHandler) postS3UploadHandler(ctx context.Context, w http.ResponseW
|
||||
acl, _ := p["acl"]
|
||||
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
|
||||
meta := http.Header{}
|
||||
meta.Set("Content-Type", "application/octet-stream")
|
||||
|
||||
@@ -107,7 +107,7 @@ func handleOIDCAuth(ctx context.Context, w http.ResponseWriter, req *http.Reques
|
||||
|
||||
func fetchOIDCCredential(ctx context.Context, req *http.Request, clientId string) (modules.SOpenIDConnectCredential, error) {
|
||||
var oidcSecret modules.SOpenIDConnectCredential
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
secret, err := modules.Credentials.GetById(s, clientId, nil)
|
||||
if err != nil {
|
||||
return oidcSecret, errors.Wrap(err, "Request Credential")
|
||||
@@ -405,7 +405,7 @@ func handleOIDCUserInfo(ctx context.Context, w http.ResponseWriter, req *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, token.Info.Region, "")
|
||||
s := auth.GetAdminSession(ctx, token.Info.Region)
|
||||
data, err := getUserInfo2(s, token.Info.UserId, token.Info.ProjectId, token.Info.Ip.String())
|
||||
if err != nil {
|
||||
httperrors.NotFoundError(ctx, w, "%v", err)
|
||||
|
||||
@@ -68,8 +68,8 @@ func getEndpointSchemeHost(endpoint string) (string, error) {
|
||||
func fetchReverseEndpoint(serviceName string) *proxy.SEndpointFactory {
|
||||
f := func(ctx context.Context, r *http.Request) (string, error) {
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r), "")
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r))
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ type Request struct {
|
||||
func newRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) *Request {
|
||||
params := appctx.AppContextParams(ctx)
|
||||
token := AppContextToken(ctx)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r), params[APIVer])
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
query, err := jsonutils.ParseQueryString(r.URL.RawQuery)
|
||||
req := &Request{
|
||||
ctx: ctx,
|
||||
|
||||
@@ -83,8 +83,8 @@ func RpcHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
token := AppContextToken(ctx)
|
||||
pathParams := appctx.AppContextParams(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), pathParams["<apiver>"])
|
||||
// pathParams := appctx.AppContextParams(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
funcname := verb + utils.Kebab2Camel(callName, "-")
|
||||
mod, e := modulebase.GetModule(s, resType)
|
||||
if e != nil || mod == nil {
|
||||
|
||||
@@ -156,7 +156,7 @@ func fetchSyslogMessage(r *http.Request) jsonutils.JSONObject {
|
||||
params.Add(jsonutils.NewString(moduleType), "service")
|
||||
}
|
||||
|
||||
sess := auth.GetAdminSession(nil, "", "")
|
||||
sess := auth.GetAdminSession(nil, "")
|
||||
logs, err := modules.Actions.List(sess, params)
|
||||
if err != nil {
|
||||
ret.Code = 2
|
||||
|
||||
Reference in New Issue
Block a user