Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller populate storage ID #8714

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ func (c *Controller) ListRepositories(w http.ResponseWriter, r *http.Request, pa
creationDate := repo.CreationDate.Unix()
r := apigen.Repository{
Id: repo.Name,
StorageId: swag.String(repo.StorageID),
StorageId: swag.String(c.getActualStorageID(repo.StorageID)),
StorageNamespace: repo.StorageNamespace,
CreationDate: creationDate,
DefaultBranch: repo.DefaultBranch,
Expand Down Expand Up @@ -2026,6 +2026,7 @@ func (c *Controller) CreateRepository(w http.ResponseWriter, r *http.Request, bo
}

// Validate storage ID exists
storageID = c.getActualStorageID(storageID)
if !slices.Contains(c.Config.StorageConfig().GetStorageIDs(), storageID) {
c.handleAPIError(ctx, w, r, graveler.ErrInvalidStorageID)
return
Expand Down Expand Up @@ -2226,6 +2227,16 @@ func (c *Controller) DeleteRepository(w http.ResponseWriter, r *http.Request, re
writeResponse(w, r, http.StatusNoContent, nil)
}

// getActualStorageID - This returns the actual storageID of the storage
func (c *Controller) getActualStorageID(storageID string) string {
if storageID == config.SingleBlockstoreID {
if storage := c.Config.StorageConfig().GetStorageByID(config.SingleBlockstoreID); storage != nil {
return storage.ID() // Will return the real actual ID
}
}
return storageID
}

func (c *Controller) GetRepository(w http.ResponseWriter, r *http.Request, repository string) {
if !c.authorize(w, r, permissions.Node{
Permission: permissions.Permission{
Expand All @@ -2244,7 +2255,7 @@ func (c *Controller) GetRepository(w http.ResponseWriter, r *http.Request, repos
CreationDate: repo.CreationDate.Unix(),
DefaultBranch: repo.DefaultBranch,
Id: repo.Name,
StorageId: swag.String(repo.StorageID),
StorageId: swag.String(c.getActualStorageID(repo.StorageID)),
StorageNamespace: repo.StorageNamespace,
ReadOnly: swag.Bool(repo.ReadOnly),
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type AdapterConfig interface {
BlockstoreAzureParams() (blockparams.Azure, error)
GetDefaultNamespacePrefix() *string
IsBackwardsCompatible() bool
ID() string
}

type Blockstore struct {
Expand Down Expand Up @@ -357,6 +358,10 @@ func (b *Blockstore) IsBackwardsCompatible() bool {
return false
}

func (b *Blockstore) ID() string {
return SingleBlockstoreID
}

func (b *Blockstore) SigningKey() SecureString {
return b.Signing.SecretKey
}
Expand Down
Loading