diff --git a/api/api.go b/api/api.go index 8063cecafb7cdf39235a16dbc5bc1d251be7e221..1272da0da2adf977f38510dc444077f603fa1cbf 100644 --- a/api/api.go +++ b/api/api.go @@ -5,6 +5,7 @@ import ( "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1" ) +// ApplyRoutes apply routes to gin engine func ApplyRoutes(r *gin.Engine, private bool) { api := r.Group("/api") { diff --git a/api/v1/auth/auth.go b/api/v1/auth/auth.go index 66fcd0a954de39aacb9c0a1c08c1ecc3c840c47f..8170bc565cafcf455438aced93ba8c62f70c7c77 100644 --- a/api/v1/auth/auth.go +++ b/api/v1/auth/auth.go @@ -16,8 +16,8 @@ import ( func ApplyRoutes(r *gin.RouterGroup) { g := r.Group("/auth") { - g.GET("/oauth2_url", oauth2_url) - g.POST("/oauth2_exchange", oauth2_exchange) + g.GET("/oauth2_url", oauth2URL) + g.POST("/oauth2_exchange", oauth2Exchange) g.GET("/user", user) g.GET("/logout", logout) } @@ -26,7 +26,7 @@ func ApplyRoutes(r *gin.RouterGroup) { /* * generate redirect url to get OAuth2 code or let client know that OAuth2 is disabled */ -func oauth2_url(c *gin.Context) { +func oauth2URL(c *gin.Context) { cacheDb := c.MustGet("cache").(*cache.Cache) state, err := util.GenerateRandomString(32) @@ -62,7 +62,7 @@ func oauth2_url(c *gin.Context) { /* * exchange code and get user infos, if OAuth2 is disable just send fake data */ -func oauth2_exchange(c *gin.Context) { +func oauth2Exchange(c *gin.Context) { var loginVals model.Auth if err := c.ShouldBind(&loginVals); err != nil { log.WithFields(log.Fields{ diff --git a/api/v1/v1.go b/api/v1/v1.go index ce1339f6e9a01ac2d1698a1767fc897038b61144..c7d5df5a119f29a8ec02c2f7b709440655300bda 100644 --- a/api/v1/v1.go +++ b/api/v1/v1.go @@ -7,6 +7,7 @@ import ( "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/server" ) +// ApplyRoutes apply routes to gin router func ApplyRoutes(r *gin.RouterGroup, private bool) { v1 := r.Group("/v1.0") { diff --git a/auth/auth.go b/auth/auth.go index f8d3e5d69e0e130a6668363939da31cce8ef8180..7deeba3a33ae7119ca470b7188d709330d8f0a6c 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,6 +11,7 @@ import ( "os" ) +// Auth interface to implement as auth provider type Auth interface { Setup() error CodeUrl(state string) string @@ -18,6 +19,7 @@ type Auth interface { UserInfo(oauth2Token *oauth2.Token) (*model.User, error) } +// GetAuthProvider get an instance of auth provider based on config func GetAuthProvider() (Auth, error) { var oauth2Client Auth var err error diff --git a/auth/fake/fake.go b/auth/fake/fake.go index 0ebe8d8218ee53ecc39dd46926518294c5431570..9c9dd938c20d525d17cecd6153958f46706d3f21 100644 --- a/auth/fake/fake.go +++ b/auth/fake/fake.go @@ -7,6 +7,7 @@ import ( "time" ) +// Fake in order to implement interface, struct is required type Fake struct{} // Setup validate provider diff --git a/auth/github/github.go b/auth/github/github.go index 5e16b2147cbd354f623236f109fadd7b02d3914f..508fd4ccf1a58608cff83d58c76e355cf2013d35 100644 --- a/auth/github/github.go +++ b/auth/github/github.go @@ -13,6 +13,7 @@ import ( "time" ) +// Github in order to implement interface, struct is required type Github struct{} var ( diff --git a/auth/oauth2oidc/oauth2oidc.go b/auth/oauth2oidc/oauth2oidc.go index 6976800e9cb92b0589d20cd45151c8c85e2f2264..6f6418acff7273c19067d634bae8ee695de0eba8 100644 --- a/auth/oauth2oidc/oauth2oidc.go +++ b/auth/oauth2oidc/oauth2oidc.go @@ -10,6 +10,7 @@ import ( "os" ) +// Oauth2idc in order to implement interface, struct is required type Oauth2idc struct{} var ( diff --git a/model/auth.go b/model/auth.go index 941dfeebc62ceaa354f14a4b19390ac2f0d02752..76fbb594533a52315d55ddcc4fa9e6359c4a0c0e 100644 --- a/model/auth.go +++ b/model/auth.go @@ -1,5 +1,6 @@ package model +// Auth structure type Auth struct { Oauth2 bool `json:"oauth2"` ClientId string `json:"clientId"` diff --git a/model/user.go b/model/user.go index 852123f69ae0b09627d2a3ff17abf509491ae83c..4dbf8acad8491b70c7049753222223b22bf68bb7 100644 --- a/model/user.go +++ b/model/user.go @@ -2,6 +2,7 @@ package model import "time" +// User structure type User struct { Sub string `json:"sub"` Name string `json:"name"` diff --git a/util/util.go b/util/util.go index c026f8441fd79ffb1be1a9a582059c4d9f2a3e35..762f497f8f06f6205471845e9059163dda5d6f72 100644 --- a/util/util.go +++ b/util/util.go @@ -11,6 +11,7 @@ import ( ) var ( + // AuthTokenHeaderName http header for token transport AuthTokenHeaderName = "x-wg-gen-web-auth" // RegexpEmail check valid email RegexpEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")