Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Turetsky committed Apr 2, 2024
1 parent b578141 commit 5110dd9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 0 additions & 2 deletions broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ func Setup(t *testing.T, ctx context.Context, egrp *errgroup.Group) {
Prefix: "/caches/" + param.Server_Hostname.GetString(),
Pubkey: string(keysetBytes),
Identity: "test_data",
Topology: false,
})
require.NoError(t, err)
err = registry.AddNamespace(&registry.Namespace{
ID: 2,
Prefix: "/foo",
Pubkey: string(keysetBytes),
Identity: "test_data",
Topology: false,
})
require.NoError(t, err)

Expand Down
3 changes: 1 addition & 2 deletions registry/migrations/20240212192712_create_db_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ CREATE TABLE IF NOT EXISTS namespace (
pubkey TEXT NOT NULL,
identity TEXT,
admin_metadata TEXT CHECK (length("admin_metadata") <= 4000),
custom_fields TEXT CHECK (length("custom_fields") <= 4000) DEFAULT '',
topology boolean
custom_fields TEXT CHECK (length("custom_fields") <= 4000) DEFAULT ''
);

CREATE TABLE IF NOT EXISTS topology (
Expand Down
17 changes: 13 additions & 4 deletions registry/registry_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Namespace struct {
Identity string `json:"identity" post:"exclude"`
AdminMetadata AdminMetadata `json:"admin_metadata" gorm:"serializer:json"`
CustomFields map[string]interface{} `json:"custom_fields" gorm:"serializer:json"`
Topology bool `json:"topology" post:"exclude"`
Topology bool `json:"topology" gorm:"=all" post:"exclude"` //This field is an extra field that's not included in the db
}

type NamespaceWOPubkey struct {
Expand Down Expand Up @@ -270,6 +270,11 @@ func getNamespaceJwksById(id int) (jwk.Set, error) {
}

func getNamespaceJwksByPrefix(prefix string) (jwk.Set, *AdminMetadata, error) {
// Note that this cannot retrieve public keys from topology as the topology table
// doesn't contain that information.
if prefix == "" {
return nil, nil, errors.New("Invalid prefix. Prefix must not be empty")
}
var result Namespace
err := db.Select("pubkey", "admin_metadata").Where("prefix = ?", prefix).Last(&result).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down Expand Up @@ -330,6 +335,10 @@ func getNamespaceById(id int) (*Namespace, error) {
}

func getNamespaceByPrefix(prefix string) (*Namespace, error) {
// This function will check the topology table first to see if the
// namespace exists there before checking the namespace table
// If the namespace exists in the topology table, it will be wrapped
// as a pelican namespace before being returned
if prefix == "" {
return nil, errors.New("Invalid prefix. Prefix must not be empty")
}
Expand All @@ -340,12 +349,12 @@ func getNamespaceByPrefix(prefix string) (*Namespace, error) {
err := db.Where("prefix = ? ", prefix).Last(&ns).Error
ns.Topology = false
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("namespace with id %q not found in database", prefix)
return nil, fmt.Errorf("namespace with prefix %q not found in database", prefix)
} else if err != nil {
return nil, errors.Wrap(err, "error retrieving pubkey")
return nil, errors.Wrap(err, "error retrieving the namespace by its prefix")
}
} else if err != nil {
return nil, errors.Wrap(err, "error retrieving pubkey")
return nil, errors.Wrap(err, "error retrieving the namespace by its prefix")
} else {
ns.ID = tp.ID
ns.Prefix = tp.Prefix
Expand Down
1 change: 0 additions & 1 deletion registry/registry_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func mockNamespace(prefix, pubkey, identity string, adminMetadata AdminMetadata)
Pubkey: pubkey,
Identity: identity,
AdminMetadata: adminMetadata,
Topology: false,
}
}

Expand Down

0 comments on commit 5110dd9

Please sign in to comment.