Merge pull request #2801 from swordqiu/hotfix/qj-apigateway-logout-handle

fix: api gateway logout handler error and fix go fmt issues
This commit is contained in:
yunion-ci-robot
2019-09-07 23:02:17 +08:00
committed by GitHub
5 changed files with 10 additions and 91 deletions
+7 -7
View File
@@ -51,13 +51,13 @@ func init() {
R(&NatGatewayListEipOptions{}, "natgateway-dnat-resources", "list resources in dnats of natgateway",
func(s *mcclient.ClientSession, opts *NatGatewayListEipOptions) error {
ret, err := modules.NatGateways.PerformAction(s, opts.ID, "dnat-resources", nil)
if err != nil {
return err
}
printObject(ret)
return nil
})
ret, err := modules.NatGateways.PerformAction(s, opts.ID, "dnat-resources", nil)
if err != nil {
return err
}
printObject(ret)
return nil
})
R(&NatGatewayListEipOptions{}, "natgateway-snat-resources", "list resources in snats of natgateway",
func(s *mcclient.ClientSession, opts *NatGatewayListEipOptions) error {
+1 -1
View File
@@ -72,6 +72,7 @@ func (h *AuthHandlers) AddMethods() {
NewHP(h.validatePasscode, "passcode"),
NewHP(h.resetTotpRecoveryQuestions, "recovery"),
NewHP(h.postLoginHandler, "login"),
NewHP(h.postLogoutHandler, "logout"),
)
// auth middleware handler
@@ -80,7 +81,6 @@ func (h *AuthHandlers) AddMethods() {
NewHP(h.getPermissionDetails, "permissions"),
NewHP(h.getAdminResources, "admin_resources"),
NewHP(h.getResources, "scoped_resources"),
NewHP(h.postLogoutHandler, "logout"),
)
h.AddByMethod(POST, FetchAuthToken,
NewHP(h.resetUserPassword, "password"),
+1 -1
View File
@@ -21,10 +21,10 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/cloudprovider"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
+1 -1
View File
@@ -21,10 +21,10 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/cloudprovider"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
-81
View File
@@ -1,81 +0,0 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"fmt"
"net/http"
"os"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/httputils"
"yunion.io/x/onecloud/pkg/util/netutils2"
)
var (
authUrl = "" // http://10.168.222.252:35357/v3
casServer = "" // https://cas.example.org/cas
serviceUrl = "" // https://app.example.com
)
func defaultPage(ctx context.Context, w http.ResponseWriter, r *http.Request) {
query, err := jsonutils.ParseQueryString(r.URL.RawQuery)
if err != nil {
httperrors.BadRequestError(w, "parse query fail %s", err)
return
}
if query.Contains("ticket") {
ticket, _ := query.GetString("ticket")
service := r.URL.Path
referer := r.Header.Get("Referer")
cliIp := netutils2.GetHttpRequestIp(r)
cli := mcclient.NewClient(authUrl, 120, true, true, "", "")
token, err := cli.AuthenticateCAS(ticket, "", "", "", cliIp)
if err != nil {
httperrors.InvalidCredentialError(w, "cas auth error %s", err)
return
}
appsrv.SendHTML(w, fmt.Sprintf("<html><h1>Welcome</h1><h2>[%s]</h2><h2>[%s]</h2><h2>[%s]</h2><h2>[%s]</h2></html>", ticket, service, referer, token.GetUserName()))
return
} else {
httperrors.HTTPError(w, fmt.Sprintf("%s/login?service=%s", casServer, serviceUrl), 302, "Redirect", httputils.Error{})
return
}
}
func main() {
if len(os.Args) <= 6 {
fmt.Printf("usage: %s <authUrl> <casServer> <serviceUrl> <certfile> <keyfile> <port>\n", os.Args[0])
os.Exit(-1)
return
}
authUrl = os.Args[1]
casServer = os.Args[2]
serviceUrl = os.Args[3]
certFile := os.Args[4] // "/etc/yunion/certs/nginx-full.crt"
keyFile := os.Args[5] // "/etc/yunion/certs/nginx.key"
port := os.Args[6] // 18443
app := appsrv.NewApplication("casfe", 1, false)
app.AddHandler("GET", "/", defaultPage)
app.ListenAndServeTLS(fmt.Sprintf("0.0.0.0:%s", port), certFile, keyFile)
}