Skip to content

Commit

Permalink
Merge pull request #6 from MZC-CSC/main
Browse files Browse the repository at this point in the history
branch sync
  • Loading branch information
raccoon-mh authored May 13, 2024
2 parents 8782669 + 5989318 commit c7dbe94
Show file tree
Hide file tree
Showing 429 changed files with 10,027 additions and 1,634 deletions.
10 changes: 10 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/go-co-op/gocron v1.28.1 h1:z2+Y094RkGriilTVdGq6IeNbTkZbGMTQSxK4zITogo0=
github.com/go-co-op/gocron v1.28.1/go.mod h1:39f6KNSGVOU1LO/ZOoZfcSxwlsJDQOKSu8erN0SH48Y=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
Expand Down Expand Up @@ -41,6 +43,8 @@ github.com/gobuffalo/validate v2.0.3+incompatible h1:6f4JCEz11Zi6iIlexMv7Jz10RBP
github.com/gobuffalo/validate/v3 v3.3.2/go.mod h1:jiEEw+N7KbAP2aInFxGnfitI0g7HjXqcp5hDD6TaQDU=
github.com/gofrs/uuid v4.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/pgconn v1.12.1/go.mod h1:ZkhRC59Llhrq3oSfrikvwQ5NaxYExr6twkdkMLaKono=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
Expand All @@ -62,13 +66,19 @@ github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
github.com/microcosm-cc/bluemonday v1.0.22/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM=
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
182 changes: 4 additions & 178 deletions mc_web_console_api/actions/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@ import (
"github.com/gobuffalo/x/sessions"
"github.com/unrolled/secure"

// gwa "github.com/gobuffalo/gocraft-work-adapter"

i18n "github.com/gobuffalo/mw-i18n/v2"
paramlogger "github.com/gobuffalo/mw-paramlogger"

// "github.com/gomodule/redigo/redis"

"mc_web_console_api/locales"
"mc_web_console_api/models"

_ "mc_web_console_api/docs" //mcone의 경우
)

// ENV is used to help switch settings based on where the
// application is being run. Default is "development".
var ENV = envy.Get("GO_ENV", "development")

var (
Expand All @@ -40,153 +31,26 @@ func App() *buffalo.App {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionStore: sessions.Null{},
PreWares: []buffalo.PreWare{
// cors.Default().Handler,
},
SessionName: "mc_web_console",
Addr: os.Getenv("API_ADDR") + ":" + os.Getenv("API_PORT"),
PreWares: []buffalo.PreWare{},
SessionName: "mc_web_console",
Addr: os.Getenv("API_ADDR") + ":" + os.Getenv("API_PORT"),
})

app.Use(forceSSL())
app.Use(paramlogger.ParameterLogger)
app.Use(contenttype.Set("application/json"))
app.Use(popmw.Transaction(models.DB))
// RoutesManager(app)

// middleware START //
// app.Use(AuthMiddleware)
// middleware END //

// controller func naming Rule
// 데이터 처리 관점으로
// 단건, 맵도 한개 : XXXData
// 목록 : XXXList
// 등록(Reg), 생성(Create), 수정(Edit), 삭제(Del), 해제(Rel) : XXXProc
apiPath := "/api"
api := app.Group(apiPath)
api.GET("/{targetController}", GetRouteController)
api.POST("/{targetController}", PostRouteController)

// API TEST
setting := app.Group(apiPath + "/setting")
namespaces := setting.Group("/namespaces")
namespace := namespaces.Group("/namespace")
namespace.GET("/list", NamespaceAllList)
namespace.POST("/reg/proc", NamespaceReg)

lu := app.Group(apiPath + "/lu")
lu.POST("/setting/resources/machineimage/lookupimage", LookupVirtualMachineImageData)

// List all configs
config := app.Group(apiPath + "/config")
config.GET("/", TbConfig)

// Get config
// configByid := app.Group(apiPath + "/config")
// configByid.GET("/", TBconfigbyId)

// loadcommonresource
loadcommonresource := app.Group(apiPath + "loadcommonresource")
loadcommonresource.GET("/", LoadCommonResource)

// [Admin] Multi-Cloud Environment Configuration
health := app.Group(apiPath + "/health")
health.GET("/", GetTBHealth)

// GET CSP Resources Overview
resources := setting.Group("/resources")
resources.GET("/inspectresourcesoverview", GetInspectResourcesOverview)

// Get value of an object
object := app.Group(apiPath + "/object")
object.GET("/", GetObjectThroughTB)

// List all objects for a given key
objects := app.Group(apiPath + "/objects")
objects.GET("/", GetObjectListThroughTB)

// [Infra service] MCIS Provisioning management
operation := app.Group(apiPath + "/operation")
manages := operation.Group("/manages")
mcismng := manages.Group("/mcismng")

// List all MCISs or MCISs' ID
mcismng.GET("/list", McisList)
// Get MCIS, Action to MCIS (status, suspend, resume, reboot, terminate, refine), or Get VMs' ID
//mcismng.GET("/", McisGet)

ns := app.Group(apiPath + "/ns")
nsid := ns.Group("/{nsid}")
mciss := nsid.Group("/mcis")
mcisid := mciss.Group("/{mcisid}")
mcisid.GET("/", McisGet)

// List SubGroup IDs in a specified MCIS
mcismng.GET("/{mcisid}"+"/subgroup", McisSubGroupList)

mcis := app.Group(apiPath + "/mcis")
mcis.GET("/mcislist", McisList)

// for the test
cluster := app.Group(apiPath + "/cluster")
cluster.GET("/ns/{nsId}/cluster", ClusterList)
cluster.POST("/ns/{nsId}/cluster", ClusterReg)
cluster.DELETE("/ns/{nsId}/cluster/{clusterId}", DelCluster)
cluster.GET("/ns/{nsId}/cluster/{clusterId}", ClusterList)
cluster.POST("/ns/{nsId}/cluster/{clusterId}/nodegroup", RegNodeGroup)
//////////////////////////////////////////////////////////////////////
// TOBE PATH

// ns

// ns/{nsid}

// benchmark

// cluster

// cmd

// control

// mcis

// mcis/{mcisid}/nlb

// mcis/{mcisid}/subgroup

// mcis/{mcisid}/vm

// monitoring

// network

// policy/mcis

// resources/customImage

// resources/dataDisk

// resources/

// resources/image

// resources/securityGroup

// resources/spec

// resources/sshKey

// resources/vNET

// object

// objects

//
// MC-IAM-MANAGER REQUIRERD

// DEBUG START //api/debug/tumblebug
// DEBUG START //
if ENV == "development" {
debug := app.Group(apiPath + "/debug")
debug.ANY("/{targetfw}/{path:.+}", DebugApiCaller)
Expand All @@ -198,47 +62,9 @@ func App() *buffalo.App {
return app
}

// middleware moved to middleware.go
// translations, forceSSL는 buffalo 에서 정의한 커스텀 미들웨어이므로 이동시키지 않음.

// translations will load locale files, set up the translator `actions.T`,
// and will return a middleware to use to load the correct locale for each
// request.
// for more information: https://gobuffalo.io/en/docs/localization
func translations() buffalo.MiddlewareFunc {
var err error
if T, err = i18n.New(locales.FS(), "en-US"); err != nil {
app.Stop(err)
}
return T.Middleware()
}

// forceSSL will return a middleware that will redirect an incoming request
// if it is not HTTPS. "http://example.com" => "https://example.com".
// This middleware does **not** enable SSL. for your application. To do that
// we recommend using a proxy: https://gobuffalo.io/en/docs/proxy
// for more information: https://github.com/unrolled/secure/
func forceSSL() buffalo.MiddlewareFunc {
return forcessl.Middleware(secure.Options{
SSLRedirect: ENV == "production",
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
})
}

// // Redirect에 route 정보 전달
// func RedirectTool(c buffalo.Context, p string) error {
// routes := app.Routes()
// for _, route := range routes {
// if route.PathName == p {
// return c.Redirect(http.StatusFound, route.Path)
// }
// }
// return c.Redirect(http.StatusFound, "/")
// }

// func alive(c buffalo.Context) error {
// return c.Render(200, r.JSON(map[string]interface{}{
// "status": "OK",
// "method": c.Request().Method,
// }))
// }
79 changes: 13 additions & 66 deletions mc_web_console_api/actions/auth.go
Original file line number Diff line number Diff line change
@@ -1,94 +1,41 @@
package actions

import (
"log"

"github.com/gobuffalo/buffalo"
"github.com/golang-jwt/jwt/v4"

"mc_web_console_api/actions/auth"
"mc_web_console_api/fwmodels/webconsole"
webconsole "mc_web_console_api/fwmodels/webconsole"
util "mc_web_console_api/util"

"github.com/gobuffalo/buffalo"
)

func AuthLogin(c buffalo.Context, commonReq *webconsole.CommonRequest) *webconsole.CommonResponse {
commonResponse := &webconsole.CommonResponse{}
var err error
func AuthLogin(c buffalo.Context, commonRequest *webconsole.CommonRequest) *webconsole.CommonResponse {
if util.MCIAM_USE {
commonResponse, err = auth.AuthMcIamLogin(c, commonReq)
if err != nil {
log.Println(err.Error())
return commonResponse
}
commonResponse := auth.AuthMcIamLogin(c, commonRequest)
return commonResponse
}
return webconsole.CommonResponseStatusInternalServerError(nil)
}

func AuthLogout(c buffalo.Context, commonReq *webconsole.CommonRequest) *webconsole.CommonResponse {
commonResponse := &webconsole.CommonResponse{}
var err error
func AuthLogout(c buffalo.Context, commonRequest *webconsole.CommonRequest) *webconsole.CommonResponse {
if util.MCIAM_USE {
commonResponse, err = auth.AuthMcIamLogout(c, commonReq)
if err != nil {
log.Println(err.Error())
return commonResponse
}
commonResponse := auth.AuthMcIamLogout(c, commonRequest)
return commonResponse
}
return webconsole.CommonResponseStatusInternalServerError(nil)
}

func AuthGetUserInfo(c buffalo.Context, commonReq *webconsole.CommonRequest) *webconsole.CommonResponse {
commonResponse := &webconsole.CommonResponse{}
var err error
if util.MCIAM_USE {
// commonResponse, err = xxx.XXXXXXXXX(c, commonReq)
if err != nil {
log.Println(err.Error())
return commonResponse
}
return commonResponse
} else {
commonResponse.ResponseData = "NO AuthGetUserInfo"
return webconsole.CommonResponseStatusInternalServerError(commonResponse)
}
}

func AuthGetUserValidate(c buffalo.Context, commonReq *webconsole.CommonRequest) *webconsole.CommonResponse {
commonResponse := &webconsole.CommonResponse{}
var err error
func AuthGetUserInfo(c buffalo.Context, commonRequest *webconsole.CommonRequest) *webconsole.CommonResponse {
if util.MCIAM_USE {
// commonResponse, err = xxx.XXXXXXXXX(c, commonReq)
if err != nil {
log.Println(err.Error())
return commonResponse
}
commonResponse := auth.AuthMcIamGetUserInfo(c, commonRequest)
return commonResponse
} else {
commonResponse.ResponseData = "NO AuthGetUserValidate"
return webconsole.CommonResponseStatusInternalServerError(commonResponse)
}
return webconsole.CommonResponseStatusInternalServerError(nil)
}

func AuthMiddleware(c buffalo.Context, commonReq *webconsole.CommonRequest) *webconsole.CommonResponse {
commonResponse := &webconsole.CommonResponse{}
var err error
func AuthGetUserValidate(c buffalo.Context, commonRequest *webconsole.CommonRequest) *webconsole.CommonResponse {
if util.MCIAM_USE {
commonResponse, err = auth.AuthMcIamMiddleware(c)
if err != nil {
log.Println(err.Error())
return commonResponse
}
commonResponse := auth.AuthMcIamGetUserValidate(c, commonRequest)
return commonResponse
} else {
commonResponse.ResponseData = "NO AuthMiddleware"
return webconsole.CommonResponseStatusInternalServerError(commonResponse)
}
}

func JwtDecode(jwtToken string) jwt.MapClaims {
claims := jwt.MapClaims{}
jwt.ParseWithClaims(jwtToken, claims, func(token *jwt.Token) (interface{}, error) { return "", nil })
return claims
return webconsole.CommonResponseStatusInternalServerError(nil)
}
Loading

0 comments on commit c7dbe94

Please sign in to comment.