Skip to content

Commit 63787dd

Browse files
committed
Rename functions to reflect their usage
1 parent a3dae32 commit 63787dd

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

registry/registry.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
***************************************************************/
1818

19-
// Package registry handles namespace management in Pelican ecosystem.
19+
// Package registry handles namespace registration in Pelican ecosystem.
2020
//
2121
// - It handles the logic to spin up a "registry" server for namespace management,
2222
// including a web UI for interactive namespace registration, approval, and browsing.
@@ -84,9 +84,7 @@ type TokenResponse struct {
8484
Error string `json:"error"`
8585
}
8686

87-
/*
88-
Various auxiliary functions used for client-server security handshakes
89-
*/
87+
// Various auxiliary functions used for client-server security handshakes
9088
type registrationData struct {
9189
ClientNonce string `json:"client_nonce"`
9290
ClientPayload string `json:"client_payload"`
@@ -301,7 +299,7 @@ func keySignChallengeCommit(ctx *gin.Context, data *registrationData, action str
301299
return sysErr
302300
}
303301

304-
err = dbAddNamespace(ctx, data)
302+
err = addNamespaceHandler(ctx, data)
305303
if err != nil {
306304
ctx.JSON(500, gin.H{"error": "The server encountered an error while attempting to add the prefix to its database"})
307305
return errors.Wrapf(err, "Failed while trying to add to database")
@@ -316,9 +314,7 @@ func keySignChallengeCommit(ctx *gin.Context, data *registrationData, action str
316314
return nil
317315
}
318316

319-
/*
320-
Handler functions called upon by the gin router
321-
*/
317+
// Handler functions called upon by the gin router
322318
func cliRegisterNamespace(ctx *gin.Context) {
323319

324320
var reqData registrationData
@@ -490,7 +486,7 @@ func cliRegisterNamespace(ctx *gin.Context) {
490486
}
491487
}
492488

493-
func dbAddNamespace(ctx *gin.Context, data *registrationData) error {
489+
func addNamespaceHandler(ctx *gin.Context, data *registrationData) error {
494490
var ns Namespace
495491
ns.Prefix = data.Prefix
496492

@@ -515,7 +511,7 @@ func dbAddNamespace(ctx *gin.Context, data *registrationData) error {
515511
return nil
516512
}
517513

518-
func dbDeleteNamespace(ctx *gin.Context) {
514+
func deleteNamespaceHandler(ctx *gin.Context) {
519515
/*
520516
A weird feature of gin is that wildcards always
521517
add a preceding /. Since the URL parsing that happens
@@ -621,7 +617,7 @@ func cliListNamespaces(c *gin.Context) {
621617
}
622618
*/
623619

624-
func dbGetAllNamespaces(ctx *gin.Context) {
620+
func getAllNamespacesHandler(ctx *gin.Context) {
625621
nss, err := getAllNamespaces()
626622
if err != nil {
627623
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "server encountered an error trying to list all namespaces"})
@@ -644,7 +640,7 @@ func wildcardHandler(ctx *gin.Context) {
644640

645641
// Equivalent of group.GET("/getNamespace")
646642
if path == "/getNamespace" {
647-
dbGetNamespace(ctx)
643+
handleGetNamespace(ctx)
648644
return
649645
}
650646

@@ -671,7 +667,7 @@ func wildcardHandler(ctx *gin.Context) {
671667
ctx.String(http.StatusNotFound, "404 Not Found")
672668
}
673669

674-
func dbGetNamespace(ctx *gin.Context) {
670+
func handleGetNamespace(ctx *gin.Context) {
675671
prefix := ctx.GetHeader("X-Pelican-Prefix")
676672
if prefix == "" {
677673
ctx.JSON(http.StatusBadRequest, gin.H{"error": "X-Pelican-Prefix header required"})
@@ -694,10 +690,10 @@ func RegisterRegistryAPI(router *gin.RouterGroup) {
694690
// routing if needed.
695691
{
696692
registryAPI.POST("", cliRegisterNamespace)
697-
registryAPI.GET("", dbGetAllNamespaces)
693+
registryAPI.GET("", getAllNamespacesHandler)
698694

699695
// Handle everything under "/" route with GET method
700696
registryAPI.GET("/*wildcard", wildcardHandler)
701-
registryAPI.DELETE("/*wildcard", dbDeleteNamespace)
697+
registryAPI.DELETE("/*wildcard", deleteNamespaceHandler)
702698
}
703699
}

registry/registry_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func TestHandleWildcard(t *testing.T) {
5151
mockJWKS := jwk.NewSet()
5252
mockJWKSBytes, err := json.Marshal(mockJWKS)
5353
require.NoError(t, err)
54-
insertMockDBData([]Namespace{{Prefix: mockPrefix, Pubkey: string(mockJWKSBytes)}})
54+
err = insertMockDBData([]Namespace{{Prefix: mockPrefix, Pubkey: string(mockJWKSBytes)}})
55+
require.NoError(t, err)
5556
mockNs, err := getNamespaceByPrefix(mockPrefix)
5657

5758
require.NoError(t, err)
@@ -64,6 +65,6 @@ func TestHandleWildcard(t *testing.T) {
6465

6566
// Should return 200 for matched metadataHandler since the db is empty
6667
assert.Equal(t, http.StatusOK, w.Code)
67-
assert.Equal(t, string(mockJWKSBytes), string(w.Body.Bytes()))
68+
assert.Equal(t, string(mockJWKSBytes), w.Body.String())
6869
})
6970
}

0 commit comments

Comments
 (0)