add comments for constructors and fix typo

This commit is contained in:
Pascal Fischer 2023-02-28 15:46:08 +01:00
parent 9d7b515b26
commit c26cd3b9fe
9 changed files with 27 additions and 22 deletions

View File

@ -23,6 +23,7 @@ type GroupsHandler struct {
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
// NewGroupsHandler creates a new GroupsHandler HTTP handler
func NewGroupsHandler(accountManager server.AccountManager, authCfg AuthCfg) *GroupsHandler { func NewGroupsHandler(accountManager server.AccountManager, authCfg AuthCfg) *GroupsHandler {
return &GroupsHandler{ return &GroupsHandler{
accountManager: accountManager, accountManager: accountManager,

View File

@ -46,7 +46,7 @@ func APIHandler(accountManager s.AccountManager, appMetrics telemetry.AppMetrics
rulesHandler := NewRulesHandler(accountManager, authCfg) rulesHandler := NewRulesHandler(accountManager, authCfg)
peersHandler := NewPeersHandler(accountManager, authCfg) peersHandler := NewPeersHandler(accountManager, authCfg)
keysHandler := NewSetupKeysHandler(accountManager, authCfg) keysHandler := NewSetupKeysHandler(accountManager, authCfg)
userHandler := NewUserHandler(accountManager, authCfg) userHandler := NewUsersHandler(accountManager, authCfg)
routesHandler := NewRoutesHandler(accountManager, authCfg) routesHandler := NewRoutesHandler(accountManager, authCfg)
nameserversHandler := NewNameserversHandler(accountManager, authCfg) nameserversHandler := NewNameserversHandler(accountManager, authCfg)
eventsHandler := NewEventsHandler(accountManager, authCfg) eventsHandler := NewEventsHandler(accountManager, authCfg)

View File

@ -20,6 +20,7 @@ type PeersHandler struct {
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
// NewPeersHandler creates a new PeersHandler HTTP handler
func NewPeersHandler(accountManager server.AccountManager, authCfg AuthCfg) *PeersHandler { func NewPeersHandler(accountManager server.AccountManager, authCfg AuthCfg) *PeersHandler {
return &PeersHandler{ return &PeersHandler{
accountManager: accountManager, accountManager: accountManager,

View File

@ -15,15 +15,15 @@ import (
"github.com/netbirdio/netbird/route" "github.com/netbirdio/netbird/route"
) )
// RoutesHanlder is the routes handler of the account // RoutesHandler is the routes handler of the account
type RoutesHanlder struct { type RoutesHandler struct {
accountManager server.AccountManager accountManager server.AccountManager
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
// NewRoutesHandler returns a new instance of RoutesHanlder handler // NewRoutesHandler returns a new instance of RoutesHandler handler
func NewRoutesHandler(accountManager server.AccountManager, authCfg AuthCfg) *RoutesHanlder { func NewRoutesHandler(accountManager server.AccountManager, authCfg AuthCfg) *RoutesHandler {
return &RoutesHanlder{ return &RoutesHandler{
accountManager: accountManager, accountManager: accountManager,
claimsExtractor: jwtclaims.NewClaimsExtractor( claimsExtractor: jwtclaims.NewClaimsExtractor(
jwtclaims.WithAudience(authCfg.Audience), jwtclaims.WithAudience(authCfg.Audience),
@ -33,7 +33,7 @@ func NewRoutesHandler(accountManager server.AccountManager, authCfg AuthCfg) *Ro
} }
// GetAllRoutes returns the list of routes for the account // GetAllRoutes returns the list of routes for the account
func (h *RoutesHanlder) GetAllRoutes(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) GetAllRoutes(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {
@ -55,7 +55,7 @@ func (h *RoutesHanlder) GetAllRoutes(w http.ResponseWriter, r *http.Request) {
} }
// CreateRoute handles route creation request // CreateRoute handles route creation request
func (h *RoutesHanlder) CreateRoute(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) CreateRoute(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {
@ -94,7 +94,7 @@ func (h *RoutesHanlder) CreateRoute(w http.ResponseWriter, r *http.Request) {
} }
// UpdateRoute handles update to a route identified by a given ID // UpdateRoute handles update to a route identified by a given ID
func (h *RoutesHanlder) UpdateRoute(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) UpdateRoute(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {
@ -160,7 +160,7 @@ func (h *RoutesHanlder) UpdateRoute(w http.ResponseWriter, r *http.Request) {
} }
// PatchRoute handles patch updates to a route identified by a given ID // PatchRoute handles patch updates to a route identified by a given ID
func (h *RoutesHanlder) PatchRoute(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) PatchRoute(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {
@ -301,7 +301,7 @@ func (h *RoutesHanlder) PatchRoute(w http.ResponseWriter, r *http.Request) {
} }
// DeleteRoute handles route deletion request // DeleteRoute handles route deletion request
func (h *RoutesHanlder) DeleteRoute(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) DeleteRoute(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {
@ -325,7 +325,7 @@ func (h *RoutesHanlder) DeleteRoute(w http.ResponseWriter, r *http.Request) {
} }
// GetRoute handles a route Get request identified by ID // GetRoute handles a route Get request identified by ID
func (h *RoutesHanlder) GetRoute(w http.ResponseWriter, r *http.Request) { func (h *RoutesHandler) GetRoute(w http.ResponseWriter, r *http.Request) {
claims := h.claimsExtractor.FromRequestContext(r) claims := h.claimsExtractor.FromRequestContext(r)
account, user, err := h.accountManager.GetAccountFromToken(claims) account, user, err := h.accountManager.GetAccountFromToken(claims)
if err != nil { if err != nil {

View File

@ -61,8 +61,8 @@ var testingAccount = &server.Account{
}, },
} }
func initRoutesTestData() *RoutesHanlder { func initRoutesTestData() *RoutesHandler {
return &RoutesHanlder{ return &RoutesHandler{
accountManager: &mock_server.MockAccountManager{ accountManager: &mock_server.MockAccountManager{
GetRouteFunc: func(_, routeID, _ string) (*route.Route, error) { GetRouteFunc: func(_, routeID, _ string) (*route.Route, error) {
if routeID == existingRouteID { if routeID == existingRouteID {

View File

@ -20,6 +20,7 @@ type RulesHandler struct {
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
// NewRulesHandler creates a new RulesHandler HTTP handler
func NewRulesHandler(accountManager server.AccountManager, authCfg AuthCfg) *RulesHandler { func NewRulesHandler(accountManager server.AccountManager, authCfg AuthCfg) *RulesHandler {
return &RulesHandler{ return &RulesHandler{
accountManager: accountManager, accountManager: accountManager,

View File

@ -20,6 +20,7 @@ type SetupKeysHandler struct {
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
// NewSetupKeysHandler creates a new SetupKeysHandler HTTP handler
func NewSetupKeysHandler(accountManager server.AccountManager, authCfg AuthCfg) *SetupKeysHandler { func NewSetupKeysHandler(accountManager server.AccountManager, authCfg AuthCfg) *SetupKeysHandler {
return &SetupKeysHandler{ return &SetupKeysHandler{
accountManager: accountManager, accountManager: accountManager,

View File

@ -14,13 +14,14 @@ import (
"github.com/netbirdio/netbird/management/server/jwtclaims" "github.com/netbirdio/netbird/management/server/jwtclaims"
) )
type UserHandler struct { type UsersHandler struct {
accountManager server.AccountManager accountManager server.AccountManager
claimsExtractor *jwtclaims.ClaimsExtractor claimsExtractor *jwtclaims.ClaimsExtractor
} }
func NewUserHandler(accountManager server.AccountManager, authCfg AuthCfg) *UserHandler { // NewUsersHandler creates a new UsersHandler HTTP handler
return &UserHandler{ func NewUsersHandler(accountManager server.AccountManager, authCfg AuthCfg) *UsersHandler {
return &UsersHandler{
accountManager: accountManager, accountManager: accountManager,
claimsExtractor: jwtclaims.NewClaimsExtractor( claimsExtractor: jwtclaims.NewClaimsExtractor(
jwtclaims.WithAudience(authCfg.Audience), jwtclaims.WithAudience(authCfg.Audience),
@ -30,7 +31,7 @@ func NewUserHandler(accountManager server.AccountManager, authCfg AuthCfg) *User
} }
// UpdateUser is a PUT requests to update User data // UpdateUser is a PUT requests to update User data
func (h *UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request) { func (h *UsersHandler) UpdateUser(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut { if r.Method != http.MethodPut {
util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w) util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w)
return return
@ -76,7 +77,7 @@ func (h *UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request) {
} }
// CreateUser creates a User in the system with a status "invited" (effectively this is a user invite). // CreateUser creates a User in the system with a status "invited" (effectively this is a user invite).
func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) { func (h *UsersHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost { if r.Method != http.MethodPost {
util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w) util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w)
return return
@ -116,7 +117,7 @@ func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
// GetAllUsers returns a list of users of the account this user belongs to. // GetAllUsers returns a list of users of the account this user belongs to.
// It also gathers additional user data (like email and name) from the IDP manager. // It also gathers additional user data (like email and name) from the IDP manager.
func (h *UserHandler) GetAllUsers(w http.ResponseWriter, r *http.Request) { func (h *UsersHandler) GetAllUsers(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet { if r.Method != http.MethodGet {
util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w) util.WriteErrorResponse("wrong HTTP method", http.StatusMethodNotAllowed, w)
return return

View File

@ -14,8 +14,8 @@ import (
"github.com/netbirdio/netbird/management/server/mock_server" "github.com/netbirdio/netbird/management/server/mock_server"
) )
func initUsers(user ...*server.User) *UserHandler { func initUsers(user ...*server.User) *UsersHandler {
return &UserHandler{ return &UsersHandler{
accountManager: &mock_server.MockAccountManager{ accountManager: &mock_server.MockAccountManager{
GetAccountFromTokenFunc: func(claims jwtclaims.AuthorizationClaims) (*server.Account, *server.User, error) { GetAccountFromTokenFunc: func(claims jwtclaims.AuthorizationClaims) (*server.Account, *server.User, error) {
users := make(map[string]*server.User, 0) users := make(map[string]*server.User, 0)