This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #164 wip initial repository and route for upload endpoint
- Loading branch information
1 parent
438a491
commit f0451a2
Showing
7 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
package collections | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/riotkit-org/backup-repository/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const KindCollection = "backupcollections" | ||
|
||
type collectionRepository struct { | ||
config config.ConfigurationProvider | ||
} | ||
|
||
// getById Returns a `kind: BackupCollection` object by it's `metadata.name` | ||
func (c *collectionRepository) getById(id string) (*Collection, error) { | ||
doc, retrieveErr := c.config.GetSingleDocument(KindCollection, id) | ||
result := Collection{} | ||
|
||
if retrieveErr != nil { | ||
return &result, errors.New(fmt.Sprintf("error retrieving result: %v", retrieveErr)) | ||
} | ||
|
||
if err := json.Unmarshal([]byte(doc), &result); err != nil { | ||
logrus.Debugln(doc) | ||
return &Collection{}, errors.New(fmt.Sprintf("cannot unmarshal response fron Kubernetes to get collection of id=%v", id)) | ||
} | ||
|
||
return &result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package collections | ||
|
||
import "github.com/riotkit-org/backup-repository/config" | ||
|
||
type Service struct { | ||
repository collectionRepository | ||
} | ||
|
||
func (s *Service) GetCollectionById(id string) (*Collection, error) { | ||
return s.repository.getById(id) | ||
} | ||
|
||
func NewService(config config.ConfigurationProvider) Service { | ||
return Service{ | ||
repository: collectionRepository{ | ||
config: config, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
package http | ||
|
||
import ( | ||
"errors" | ||
"github.com/gin-gonic/gin" | ||
"github.com/riotkit-org/backup-repository/core" | ||
) | ||
|
||
func addUploadRoute(r *gin.RouterGroup, ctx *core.ApplicationContainer) { | ||
r.POST("/repository/collection/:collectionId/version", func(c *gin.Context) { | ||
// todo: check if collection exists | ||
// todo: check if backup window is OK | ||
// todo: check if rotation strategy allows uploading | ||
// todo: deactivate token if temporary token is used | ||
// todo: handle upload | ||
// todo: check uploaded file size, respect quotas and additional space | ||
// todo: check if there are gpg header and footer | ||
// todo: handle upload interruptions | ||
|
||
collection, err := ctx.Collections.GetCollectionById(c.Param("collectionId")) | ||
if err != nil { | ||
NotFoundResponse(c, errors.New("cannot find specified collection")) | ||
return | ||
} | ||
|
||
println(collection) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters