Skip to content

Commit

Permalink
fix: consistent func naming
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 25, 2025
1 parent d74cc09 commit bf4c656
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/vela-server/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func metadataVela(c *cli.Context) (*internal.Vela, error) {
}

if len(c.StringSlice("cors-allow-origins")) > 0 {
vela.CORSAllowOrigins = c.StringSlice("cors-allow-origins")
vela.CorsAllowOrigins = c.StringSlice("cors-allow-origins")
}

if len(c.String("webui-oauth-callback")) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type (
AccessTokenDuration time.Duration `json:"access_token_duration"`
RefreshTokenDuration time.Duration `json:"refresh_token_duration"`
OpenIDIssuer string `json:"oidc_issuer"`
CORSAllowOrigins []string `json:"cors_allow_origins"`
CorsAllowOrigins []string `json:"cors_allow_origins"`
}

// Metadata is the extra set of data passed to the compiler for
Expand Down
10 changes: 5 additions & 5 deletions router/middleware/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Options(c *gin.Context) {
} else {
c.Header("Access-Control-Allow-Origin", "*")

origin := CORSAllowOrigin(c, m)
origin := CorsAllowOrigin(c, m)
if len(origin) > 0 {
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Credentials", "true")
Expand Down Expand Up @@ -66,7 +66,7 @@ func Cors(c *gin.Context) {

c.Header("Access-Control-Allow-Origin", "*")

origin := CORSAllowOrigin(c, m)
origin := CorsAllowOrigin(c, m)
if len(origin) > 0 {
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Credentials", "true")
Expand All @@ -75,13 +75,13 @@ func Cors(c *gin.Context) {
c.Header("Access-Control-Expose-Headers", "link, x-total-count")
}

// CORSAllowOrigin is a helper function that returns the
// CorsAllowOrigin is a helper function that returns the
// allowed origin for CORS requests by checking the
// request origin against the allowed origins in the
// Vela metadata.
func CORSAllowOrigin(c *gin.Context, m *internal.Metadata) string {
func CorsAllowOrigin(c *gin.Context, m *internal.Metadata) string {
origin := c.Request.Header.Get("Origin")
for _, domain := range m.Vela.CORSAllowOrigins {
for _, domain := range m.Vela.CorsAllowOrigins {
if domain == origin {
return domain
}
Expand Down
8 changes: 4 additions & 4 deletions router/middleware/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestMiddleware_Cors(t *testing.T) {
m: &internal.Metadata{
Vela: &internal.Vela{
Address: "http://localhost:8080",
CORSAllowOrigins: []string{},
CorsAllowOrigins: []string{},
},
},
origin: "http://localhost:8888",
Expand All @@ -202,7 +202,7 @@ func TestMiddleware_Cors(t *testing.T) {
m: &internal.Metadata{
Vela: &internal.Vela{
WebAddress: "http://localhost:8888",
CORSAllowOrigins: []string{},
CorsAllowOrigins: []string{},
},
},
origin: "http://localhost:8888",
Expand All @@ -215,7 +215,7 @@ func TestMiddleware_Cors(t *testing.T) {
m: &internal.Metadata{
Vela: &internal.Vela{
WebAddress: "http://localhost:8888",
CORSAllowOrigins: []string{"http://localhost:3000", "http://localhost:3001"},
CorsAllowOrigins: []string{"http://localhost:3000", "http://localhost:3001"},
},
},
origin: "http://localhost:8888",
Expand All @@ -228,7 +228,7 @@ func TestMiddleware_Cors(t *testing.T) {
m: &internal.Metadata{
Vela: &internal.Vela{
WebAddress: "",
CORSAllowOrigins: []string{"http://localhost:3000", "http://localhost:3001", "http://localhost:8888"},
CorsAllowOrigins: []string{"http://localhost:3000", "http://localhost:3001", "http://localhost:8888"},
},
},
origin: "http://localhost:8888",
Expand Down

0 comments on commit bf4c656

Please sign in to comment.