Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
feat: #164 wip initial repository and route for upload endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Feb 13, 2022
1 parent 438a491 commit f0451a2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
1 change: 0 additions & 1 deletion server-go/collections/action.go

This file was deleted.

31 changes: 31 additions & 0 deletions server-go/collections/repository.go
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
}
19 changes: 19 additions & 0 deletions server-go/collections/service.go
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,
},
}
}
2 changes: 2 additions & 0 deletions server-go/core/ctx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"github.com/riotkit-org/backup-repository/collections"
"github.com/riotkit-org/backup-repository/config"
"github.com/riotkit-org/backup-repository/security"
"github.com/riotkit-org/backup-repository/users"
Expand All @@ -10,5 +11,6 @@ type ApplicationContainer struct {
Config *config.ConfigurationProvider
Users *users.Service
GrantedAccesses *security.Service
Collections *collections.Service
JwtSecretKey string
}
27 changes: 27 additions & 0 deletions server-go/http/collection.go
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)
})
}
1 change: 1 addition & 0 deletions server-go/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func SpawnHttpApplication(ctx *core.ApplicationContainer) {
addWhoamiRoute(router, ctx)
addLogoutRoute(router, ctx)
addGrantedAccessSearchRoute(router, ctx)
addUploadRoute(router, ctx)
}

_ = r.Run()
Expand Down
3 changes: 3 additions & 0 deletions server-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/jessevdk/go-flags"
"github.com/riotkit-org/backup-repository/collections"
"github.com/riotkit-org/backup-repository/config"
"github.com/riotkit-org/backup-repository/core"
"github.com/riotkit-org/backup-repository/db"
Expand Down Expand Up @@ -66,12 +67,14 @@ func main() {

usersService := users.NewUsersService(configProvider)
gaService := security.NewService(dbDriver)
collectionsService := collections.NewService(configProvider)

ctx := core.ApplicationContainer{
Config: &configProvider,
Users: &usersService,
GrantedAccesses: &gaService,
JwtSecretKey: opts.JwtSecretKey,
Collections: &collectionsService,
}

// todo: First thread - HTTP
Expand Down

0 comments on commit f0451a2

Please sign in to comment.