Skip to content

Commit b9a81ca

Browse files
committed
Updated endoint scopes
1 parent 1a10945 commit b9a81ca

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

pkg/handler/auth/endpoints.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func (service *auth) AddEndpoints(ctx context.Context, r server.Router) {
5151
// Scopes: write // TODO: Add scopes
5252
// Description: Create a new token
5353
r.AddHandlerFuncRe(ctx, reRoot, service.CreateToken, http.MethodPost).(router.Route).
54-
SetScope(service.ScopeRead()...).
5554
SetScope(service.ScopeWrite()...)
5655

5756
// Path: /<token-name>
@@ -66,7 +65,6 @@ func (service *auth) AddEndpoints(ctx context.Context, r server.Router) {
6665
// Scopes: write // TODO: Add scopes
6766
// Description: Delete or update a token
6867
r.AddHandlerFuncRe(ctx, reToken, service.UpdateToken, http.MethodDelete, http.MethodPatch).(router.Route).
69-
SetScope(service.ScopeRead()...).
7068
SetScope(service.ScopeWrite()...)
7169

7270
}

pkg/handler/nginx/endpoints.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,48 @@ var (
5050
// PUBLIC METHODS - ENDPOINTS
5151

5252
// Add endpoints to the router
53-
func (service *nginx) AddEndpoints(ctx context.Context, router server.Router) {
53+
func (service *nginx) AddEndpoints(ctx context.Context, r server.Router) {
5454
// Path: /
5555
// Methods: GET
56-
// Scopes: read // TODO: Add scopes
56+
// Scopes: read
5757
// Description: Get nginx status (version, uptime, available and enabled configurations)
58-
router.AddHandlerFuncRe(ctx, reRoot, service.GetHealth, http.MethodGet)
58+
r.AddHandlerFuncRe(ctx, reRoot, service.GetHealth, http.MethodGet).(router.Route).
59+
SetScope(service.ScopeRead()...)
5960

6061
// Path: /(test|reload|reopen)
6162
// Methods: PUT
62-
// Scopes: write // TODO: Add scopes
63+
// Scopes: write
6364
// Description: Test, reload and reopen nginx configuration
64-
router.AddHandlerFuncRe(ctx, reAction, service.PutAction, http.MethodPut)
65+
r.AddHandlerFuncRe(ctx, reAction, service.PutAction, http.MethodPut).(router.Route).
66+
SetScope(service.ScopeWrite()...)
6567

6668
// Path: /config
6769
// Methods: GET
68-
// Scopes: read // TODO: Add scopes
70+
// Scopes: read
6971
// Description: Read the current set of configurations
70-
router.AddHandlerFuncRe(ctx, reListConfig, service.ListConfig, http.MethodGet)
72+
r.AddHandlerFuncRe(ctx, reListConfig, service.ListConfig, http.MethodGet).(router.Route).
73+
SetScope(service.ScopeRead()...)
7174

7275
// Path: /config
7376
// Methods: POST
74-
// Scopes: read // TODO: Add scopes
77+
// Scopes: write
7578
// Description: Create a new configuration
76-
router.AddHandlerFuncRe(ctx, reListConfig, service.CreateConfig, http.MethodPost)
79+
r.AddHandlerFuncRe(ctx, reListConfig, service.CreateConfig, http.MethodPost).(router.Route).
80+
SetScope(service.ScopeWrite()...)
7781

7882
// Path: /config/{id}
7983
// Methods: GET
80-
// Scopes: read // TODO: Add scopes
84+
// Scopes: read
8185
// Description: Read a configuration
82-
router.AddHandlerFuncRe(ctx, reConfig, service.ReadConfig, http.MethodGet)
86+
r.AddHandlerFuncRe(ctx, reConfig, service.ReadConfig, http.MethodGet).(router.Route).
87+
SetScope(service.ScopeRead()...)
8388

8489
// Path: /config/{id}
8590
// Methods: DELETE, POST, PATCH
86-
// Scopes: write // TODO: Add scopes
91+
// Scopes: write
8792
// Description: Modify a configuration
88-
router.AddHandlerFuncRe(ctx, reConfig, service.WriteConfig, http.MethodDelete, http.MethodPatch)
93+
r.AddHandlerFuncRe(ctx, reConfig, service.WriteConfig, http.MethodDelete, http.MethodPatch).(router.Route).
94+
SetScope(service.ScopeWrite()...)
8995
}
9096

9197
///////////////////////////////////////////////////////////////////////////////

pkg/handler/nginx/scope.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package nginx
2+
3+
import (
4+
// Packages
5+
"github.com/mutablelogic/go-server/pkg/version"
6+
)
7+
8+
////////////////////////////////////////////////////////////////////////////////
9+
// GLOBALS
10+
11+
var (
12+
// Prefix
13+
scopePrefix = version.GitSource + "/scope/"
14+
)
15+
16+
////////////////////////////////////////////////////////////////////////////////
17+
// PUBLIC METHODS
18+
19+
func (nginx *nginx) ScopeRead() []string {
20+
// Return read (list, get) scopes
21+
return []string{
22+
scopePrefix + nginx.Label() + "/read",
23+
scopePrefix + defaultName + "/read",
24+
}
25+
}
26+
27+
func (nginx *nginx) ScopeWrite() []string {
28+
// Return write (create, delete, update) scopes
29+
return []string{
30+
scopePrefix + nginx.Label() + "/write",
31+
scopePrefix + defaultName + "/write",
32+
}
33+
}

0 commit comments

Comments
 (0)