Skip to content

Commit ac46204

Browse files
authored
Merge pull request #28 from MZC-CSC/feature_standalone
Feature standalone
2 parents 9df3483 + 013a3da commit ac46204

14 files changed

+38
-25
lines changed

.gitignore

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ api/!.yarn/sdks
3434
api/!.yarn/versions
3535

3636

37-
3837
# front
3938

4039
## env
@@ -68,14 +67,15 @@ front/.idea
6867

6968
# bin
7069
bin/mc-web-console-api
70+
bin/mc-web-console-api.pid
71+
bin/mc-web-console-api.log
7172
bin/.env
7273

74+
# conf
75+
conf/api.yaml
76+
conf/selfiamauthsetting.yaml
77+
conf/selfiamuser.dat
78+
conf/serverinfo
79+
80+
# scripts
7381
scripts/.env
74-
api/conf/api.yaml
75-
bin/mc-web-console-api.log
76-
bin/conf/api.yaml
77-
api/conf/serverinfo
78-
api/conf/cmiguser.dat
79-
api/conf/cmigauthsetting.yaml
80-
api/conf/selfiamuser.dat
81-
api/conf/selfiamauthsetting.yaml

api/actions/app.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func App() *buffalo.App {
3838
SessionName: "mc_web_console",
3939
Addr: os.Getenv("API_ADDR") + ":" + os.Getenv("API_PORT"),
4040
})
41-
4241
app.Use(paramlogger.ParameterLogger)
4342
app.Use(contenttype.Set("application/json"))
4443
app.Use(popmw.Transaction(models.DB))

api/actions/auth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ func AuthLoginRefresh(c buffalo.Context) error {
5353
userId := c.Value("UserId").(string)
5454
sess, err := self.GetUserByUserId(tx, userId)
5555
if err != nil {
56-
log.Println(err.Error())
56+
app.Logger.Error(err.Error())
5757
commonResponse := handler.CommonResponseStatusBadRequest(err.Error())
5858
return c.Render(commonResponse.Status.StatusCode, r.JSON(commonResponse))
5959
}
6060

6161
tokenSet, err := self.RefreshAccessToken(sess.RefreshToken)
6262
if err != nil {
63-
log.Println(err.Error())
63+
app.Logger.Error(err.Error())
6464
commonResponse := handler.CommonResponseStatusBadRequest(err.Error())
6565
return c.Render(commonResponse.Status.StatusCode, r.JSON(commonResponse))
6666
}
@@ -72,7 +72,7 @@ func AuthLoginRefresh(c buffalo.Context) error {
7272

7373
_, err = self.UpdateUserSess(tx, sess)
7474
if err != nil {
75-
log.Println(err.Error())
75+
app.Logger.Error(err.Error())
7676
commonResponse := handler.CommonResponseStatusBadRequest(err.Error())
7777
return c.Render(commonResponse.Status.StatusCode, r.JSON(commonResponse))
7878
}

api/actions/middleware.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package actions
22

33
import (
44
"fmt"
5-
"log"
65
"mc_web_console_api/handler/self"
76
"net/http"
87
"strings"
@@ -18,7 +17,7 @@ func DefaultMiddleware(next buffalo.Handler) buffalo.Handler {
1817
accessToken := strings.TrimPrefix(c.Request().Header.Get("Authorization"), "Bearer ")
1918
claims, err := self.GetCmigTokenClaims(accessToken)
2019
if err != nil {
21-
log.Println(err.Error())
20+
app.Logger.Error(err.Error())
2221
return c.Render(http.StatusUnauthorized, render.JSON(map[string]interface{}{"error": "Unauthorized"}))
2322
}
2423
tx := c.Value("tx").(*pop.Connection)

api/go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ require (
1616
github.com/gobuffalo/validate/v3 v3.3.3
1717
github.com/gobuffalo/x v0.1.0
1818
github.com/gofrs/uuid v4.4.0+incompatible
19+
github.com/golang-jwt/jwt/v5 v5.2.1
1920
github.com/m-cmp/mc-iam-manager v0.2.10
2021
github.com/opentracing/opentracing-go v1.2.0
2122
github.com/rs/cors v1.11.0
2223
github.com/spf13/viper v1.19.0
24+
golang.org/x/crypto v0.26.0
25+
gopkg.in/yaml.v2 v2.4.0
2326
)
2427

2528
require (
@@ -46,7 +49,6 @@ require (
4649
github.com/gobuffalo/refresh v1.13.3 // indirect
4750
github.com/gobuffalo/tags/v3 v3.1.4 // indirect
4851
github.com/goccy/go-json v0.10.3 // indirect
49-
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
5052
github.com/gorilla/css v1.0.1 // indirect
5153
github.com/gorilla/handlers v1.5.2 // indirect
5254
github.com/gorilla/mux v1.8.1 // indirect
@@ -99,7 +101,6 @@ require (
99101
github.com/subosito/gotenv v1.6.0 // indirect
100102
go.uber.org/atomic v1.9.0 // indirect
101103
go.uber.org/multierr v1.9.0 // indirect
102-
golang.org/x/crypto v0.26.0 // indirect
103104
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
104105
golang.org/x/mod v0.18.0 // indirect
105106
golang.org/x/net v0.26.0 // indirect
@@ -109,6 +110,5 @@ require (
109110
golang.org/x/text v0.17.0 // indirect
110111
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
111112
gopkg.in/ini.v1 v1.67.0 // indirect
112-
gopkg.in/yaml.v2 v2.4.0 // indirect
113113
gopkg.in/yaml.v3 v3.0.1 // indirect
114114
)

api/handler/http-util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
func init() {
7070
viper.SetConfigName("api")
7171
viper.SetConfigType("yaml")
72-
viper.AddConfigPath("conf")
72+
viper.AddConfigPath("../conf")
7373

7474
if err := viper.ReadInConfig(); err != nil {
7575
panic(fmt.Errorf("fatal error reading actions/conf/api.yaml file: %s", err))

api/handler/mciammanager/middleware.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func DefaultMiddleware(next buffalo.Handler) buffalo.Handler {
4848
err := iamtokenvalidator.IsTokenValid(accessToken)
4949
if err != nil {
5050
log.Println(err.Error())
51-
return c.Render(http.StatusInternalServerError, render.JSON(map[string]interface{}{"error": err.Error()}))
51+
return c.Render(http.StatusUnauthorized, render.JSON(map[string]interface{}{"error": err.Error()}))
5252
}
5353
claims, err := iamtokenvalidator.GetTokenClaimsByIamManagerClaims(accessToken)
5454
if err != nil {

api/handler/self/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var (
4040
CmigUser *User
4141
cmigAuthSetting CmigAuthSetting
4242
encryptionKey []byte
43-
datfilename = "conf/selfiamuser.dat"
44-
conffilename = "conf/selfiamauthsetting.yaml"
43+
datfilename = "../conf/selfiamuser.dat"
44+
conffilename = "../conf/selfiamauthsetting.yaml"
4545
)
4646

4747
func init() {

api/handler/self/menu.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func buildMenuTree(menus Menus, parentID string) Menus {
5555
}
5656

5757
func createMenuResource() error {
58-
yamlFile := "./conf/selfiammenu.yaml"
58+
yamlFile := "../conf/selfiammenu.yaml"
5959

6060
data, err := os.ReadFile(yamlFile)
6161
if err != nil {
@@ -170,8 +170,7 @@ func getCreateWebMenuByYamlEndpoint() string {
170170
log.Fatalf("Error reading config file, %s", err)
171171
}
172172
baseUrl := viper.Get("services.mc-iam-manager.baseurl").(string)
173-
createwebmenubyyamlUri := viper.Get("serviceActions.mc-iam-manager.Createwebmenubyyaml.resourcePath").(string)
173+
createwebmenubyyamlUri := viper.Get("serviceActions.mc-iam-manager.Createmenuresourcesbymenuyaml.resourcePath").(string)
174174
urlModified := strings.ReplaceAll(baseUrl+createwebmenubyyamlUri, "{framework}", "web")
175-
fmt.Println("Createwebmenubyyaml Endpoint is : ", urlModified)
176175
return urlModified
177176
}

bin/.env.sample

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
API_ADDR=0.0.0.0
2+
API_PORT=3000
3+
4+
DATABASE_USER=DATABASE_USER # Please CHANGE ME (REQUIRE)
5+
DATABASE_PASS=DATABASE_PASS # Please CHANGE ME (REQUIRE)
6+
DATABASE_HOST=DATABASE_HOST # Please CHANGE ME (REQUIRE)
7+
DATABASE=DATABASE # Please CHANGE ME (REQUIRE)
8+
DEV_DATABASE_URL=postgres://${DATABASE_USER}:${DATABASE_PASS}@${DATABASE_HOST}:5432/${DATABASE}
9+
10+
PROD_DATABASE_USER=DATABASE_USER # Please CHANGE ME (REQUIRE)
11+
PROD_DATABASE_PASS=DATABASE_PASS # Please CHANGE ME (REQUIRE)
12+
PROD_DATABASE_HOST=DATABASE_HOST # Please CHANGE ME (REQUIRE)
13+
PROD_DATABASE=DATABASE # Please CHANGE ME (REQUIRE)
14+
PROD_DATABASE_URL=postgres://${DATABASE_USER}:${DATABASE_PASS}@${DATABASE_HOST}:5432/${DATABASE}
15+
16+
MCIAM_USE=true
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)