1.delete apiversion and kind in property
2.alter function in registries 3.alter path
This commit is contained in:
@@ -20,18 +20,33 @@ import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/filter/route"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Register(ws *restful.WebService,subPath string) {
|
||||
func Register(ws *restful.WebService, subPath string) {
|
||||
|
||||
ws.Route(ws.POST(subPath+"/login").To(models.RegistryLoginAuth).Filter(route.RouteLogging)).
|
||||
Consumes(restful.MIME_JSON).
|
||||
Produces(restful.MIME_JSON)
|
||||
|
||||
ws.Route(ws.POST(subPath+"/key").To(models.RegistryKey).Filter(route.RouteLogging)).
|
||||
ws.Route(ws.POST(subPath + "/validation").To(handlerRegistryValidation).Filter(route.RouteLogging)).
|
||||
Consumes(restful.MIME_JSON).
|
||||
Produces(restful.MIME_JSON)
|
||||
|
||||
}
|
||||
|
||||
func handlerRegistryValidation(request *restful.Request, response *restful.Response) {
|
||||
|
||||
authinfo := models.AuthInfo{}
|
||||
|
||||
err := request.ReadEntity(&authinfo)
|
||||
|
||||
if err != nil {
|
||||
|
||||
response.WriteError(http.StatusInternalServerError, err)
|
||||
|
||||
}
|
||||
|
||||
result := models.RegistryLoginAuth(authinfo)
|
||||
|
||||
response.WriteAsJson(result)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package constants
|
||||
|
||||
type ResultMessage struct {
|
||||
|
||||
Kind string `json:"kind"`
|
||||
ApiVersion string `json:"apiVersion"`
|
||||
Data interface{} `json:"data"`
|
||||
|
||||
|
||||
|
||||
@@ -18,14 +18,12 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/emicklei/go-restful"
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/api/types"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"github.com/golang/glog"
|
||||
|
||||
)
|
||||
|
||||
@@ -37,114 +35,60 @@ type AuthInfo struct {
|
||||
}
|
||||
|
||||
|
||||
func RegistryLoginAuth(request *restful.Request, response *restful.Response) {
|
||||
const DOCKERCLIENTERROR = "Docker client error"
|
||||
|
||||
func RegistryLoginAuth(authinfo AuthInfo) constants.ResultMessage {
|
||||
|
||||
var result constants.ResultMessage
|
||||
|
||||
authinfo := AuthInfo{}
|
||||
data := make(map[string]interface{})
|
||||
|
||||
err := request.ReadEntity(&authinfo)
|
||||
datastr := []byte(authinfo.Username + ":" + authinfo.Password)
|
||||
auth := base64.StdEncoding.EncodeToString(datastr)
|
||||
ctx := context.Background()
|
||||
cli, err := client.NewClientWithOpts()
|
||||
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
|
||||
datastr := []byte(authinfo.Username + ":" + authinfo.Password)
|
||||
auth := base64.StdEncoding.EncodeToString(datastr)
|
||||
ctx := context.Background()
|
||||
cli, err := client.NewEnvClient()
|
||||
data["message"] = DOCKERCLIENTERROR
|
||||
data["reason"] = err.Error()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
authcfg := types.AuthConfig{
|
||||
|
||||
authcfg := types.AuthConfig{
|
||||
Username: authinfo.Username,
|
||||
Password: authinfo.Password,
|
||||
Auth: auth,
|
||||
ServerAddress: authinfo.ServerHost,
|
||||
}
|
||||
|
||||
Username: authinfo.Username,
|
||||
Password: authinfo.Password,
|
||||
Auth: auth,
|
||||
ServerAddress: authinfo.ServerHost,
|
||||
}
|
||||
authmsg, err := cli.RegistryLogin(ctx, authcfg)
|
||||
|
||||
auth_msg, err := cli.RegistryLogin(ctx, authcfg)
|
||||
data := make(map[string]string)
|
||||
cli.Close()
|
||||
|
||||
if err == nil {
|
||||
|
||||
|
||||
data["status"] = auth_msg.Status
|
||||
result.Data = data
|
||||
result.ApiVersion = constants.APIVERSION
|
||||
result.Kind = constants.KIND
|
||||
glog.Infoln(result)
|
||||
response.WriteAsJson(result)
|
||||
} else {
|
||||
|
||||
|
||||
data["status"] = "Login Failed"
|
||||
result.Data = data
|
||||
result.ApiVersion = constants.APIVERSION
|
||||
result.Kind = constants.KIND
|
||||
glog.Infoln(result)
|
||||
response.WriteAsJson(result)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
result.Data = err
|
||||
result.ApiVersion = constants.APIVERSION
|
||||
result.Kind = constants.KIND
|
||||
glog.Infoln(result)
|
||||
response.WriteAsJson(result)
|
||||
if err != nil {
|
||||
|
||||
data["message"] = DOCKERCLIENTERROR
|
||||
data["reason"] = err.Error()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func RegistryKey(request *restful.Request, response *restful.Response) {
|
||||
|
||||
|
||||
var result constants.ResultMessage
|
||||
|
||||
authinfo := AuthInfo{}
|
||||
|
||||
|
||||
|
||||
err := request.ReadEntity(&authinfo)
|
||||
|
||||
if err == nil {
|
||||
|
||||
datastr := []byte(authinfo.Username + ":" + authinfo.Password)
|
||||
auth := base64.StdEncoding.EncodeToString(datastr)
|
||||
|
||||
dockercfg := "{\"auths\":{\""+authinfo.ServerHost+"\":{\"username\":\""+authinfo.Username+"\",\"password\":\""+authinfo.Password+"\",\"auth\":\""+auth+"\"}}}"
|
||||
|
||||
dockerconfigjson := base64.StdEncoding.EncodeToString([]byte(dockercfg))
|
||||
|
||||
|
||||
data := make(map[string]string)
|
||||
|
||||
data["dockerconfigjson"] = dockerconfigjson
|
||||
|
||||
result.Data = data
|
||||
|
||||
result.ApiVersion = constants.APIVERSION
|
||||
result.Kind = constants.KIND
|
||||
|
||||
glog.Infoln(result)
|
||||
|
||||
response.WriteAsJson(result)
|
||||
if authmsg.Status == "Login Succeeded" {
|
||||
|
||||
data["message"] = "Verified"
|
||||
|
||||
} else {
|
||||
|
||||
data["message"] = "Unverified"
|
||||
data["reason"] = "Username or password is incorrect "
|
||||
|
||||
result.Data = err
|
||||
result.ApiVersion = constants.APIVERSION
|
||||
result.Kind = constants.KIND
|
||||
glog.Infoln(result)
|
||||
response.WriteAsJson(result)
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ func GetPvcListBySc(request *restful.Request, response *restful.Response) {
|
||||
response.WriteError(http.StatusInternalServerError, err)
|
||||
}
|
||||
result := constants.ResultMessage{
|
||||
Kind: constants.KIND,
|
||||
ApiVersion: constants.APIVERSION,
|
||||
|
||||
Data: pvcListBySc{scName, claims}}
|
||||
|
||||
response.WriteAsJson(result)
|
||||
@@ -50,8 +49,7 @@ func GetScMetrics(request *restful.Request, response *restful.Response) {
|
||||
response.WriteError(http.StatusInternalServerError, err)
|
||||
}
|
||||
result := constants.ResultMessage{
|
||||
Kind: constants.KIND,
|
||||
ApiVersion: constants.APIVERSION,
|
||||
|
||||
Data: scMetrics{Name: scName, Metrics: metrics},
|
||||
}
|
||||
response.WriteAsJson(result)
|
||||
|
||||
@@ -26,8 +26,7 @@ func GetPodListByPvc(request *restful.Request, response *restful.Response) {
|
||||
response.WriteError(http.StatusInternalServerError, err)
|
||||
}
|
||||
result := constants.ResultMessage{
|
||||
Kind: constants.KIND,
|
||||
ApiVersion: constants.APIVERSION,
|
||||
|
||||
Data: podListByPvc{
|
||||
Name: pvcName, Namespace: nsName, Pods: pods}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user