mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 12:50:21 -06:00
Basic implementation of CS3 [WIP]
This commit is contained in:
committed by
Benedikt Kulmann
parent
f6732fd14e
commit
901ada3ffc
@@ -228,9 +228,9 @@ func (s Service) DeleteGroup(c context.Context, in *proto.DeleteGroupRequest, ou
|
||||
s.log.Error().Err(err).Str("groupid", id).Str("accountid", g.Members[i].Id).Msg("could not remove account memberof, skipping")
|
||||
}
|
||||
}
|
||||
if err = os.Remove(path); err != nil {
|
||||
s.log.Error().Err(err).Str("id", id).Str("path", path).Msg("could not remove group")
|
||||
return merrors.InternalServerError(s.id, "could not remove group: %v", err.Error())
|
||||
|
||||
if err = s.repo.DeleteGroup(c, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = s.index.Delete(id); err != nil {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
merrors "github.com/micro/go-micro/v2/errors"
|
||||
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -95,19 +96,147 @@ func (r CS3Repo) LoadAccount(ctx context.Context, id string, a *proto.Account) (
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
|
||||
if _, err = cl.Do(ureq); err != nil {
|
||||
resp, err := cl.Do(ureq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := json.Unmarshal(b, &a); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) {
|
||||
t, err := r.authenticate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
|
||||
|
||||
ureq, err := http.NewRequest("DELETE", fmt.Sprintf("http://localhost:9187/data/accounts/%s", id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ureq.Header.Add("x-access-token", t)
|
||||
cl := http.Client{
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
|
||||
resp, err := cl.Do(ureq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) {
|
||||
t, err := r.authenticate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
|
||||
|
||||
ureq, err := http.NewRequest("DELETE", fmt.Sprintf("http://localhost:9187/data/groups/%s", id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ureq.Header.Add("x-access-token", t)
|
||||
cl := http.Client{
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
|
||||
resp, err := cl.Do(ureq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) WriteGroup(ctx context.Context, g *proto.Group) (err error) {
|
||||
panic("implement me")
|
||||
t, err := r.authenticate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
|
||||
if err := r.makeRootDirIfNotExist(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var by []byte
|
||||
if by, err = json.Marshal(g); err != nil {
|
||||
return merrors.InternalServerError(r.serviceID, "could not marshal account: %v", err.Error())
|
||||
}
|
||||
|
||||
ureq, err := http.NewRequest("PUT", fmt.Sprintf("http://localhost:9187/data/groups/%s", g.Id), bytes.NewReader(by))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ureq.Header.Add("x-access-token", t)
|
||||
cl := http.Client{
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
|
||||
if _, err := cl.Do(ureq); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err error) {
|
||||
panic("implement me")
|
||||
t, err := r.authenticate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
|
||||
|
||||
ureq, err := http.NewRequest("GET", fmt.Sprintf("http://localhost:9187/data/groups/%s", id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ureq.Header.Add("x-access-token", t)
|
||||
cl := http.Client{
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
|
||||
resp, err := cl.Do(ureq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := json.Unmarshal(b, &g); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r CS3Repo) authenticate(ctx context.Context) (token string, err error) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
"github.com/rs/zerolog"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
@@ -115,6 +116,26 @@ func (r DiskRepo) deflateMemberOf(a *proto.Account) {
|
||||
a.MemberOf = deflated
|
||||
}
|
||||
|
||||
func (r DiskRepo) DeleteAccount(ctx context.Context, id string) (err error) {
|
||||
path := filepath.Join(r.dataPath, "accounts", id)
|
||||
if err = os.Remove(path); err != nil {
|
||||
r.log.Error().Err(err).Str("id", id).Str("path", path).Msg("could not remove account")
|
||||
return merrors.InternalServerError(r.serviceID, "could not remove account: %v", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r DiskRepo) DeleteGroup(ctx context.Context, id string) (err error) {
|
||||
path := filepath.Join(r.dataPath, "groups", id)
|
||||
if err = os.Remove(path); err != nil {
|
||||
r.log.Error().Err(err).Str("id", id).Str("path", path).Msg("could not remove group")
|
||||
return merrors.InternalServerError(r.serviceID, "could not remove group: %v", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// deflateMembers replaces the users of a group with an instance that only contains the id
|
||||
func (r DiskRepo) deflateMembers(g *proto.Group) {
|
||||
if g == nil {
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
type Repo interface {
|
||||
WriteAccount(ctx context.Context, a *proto.Account) (err error)
|
||||
LoadAccount(ctx context.Context, id string, a *proto.Account) (err error)
|
||||
DeleteAccount(ctx context.Context, id string) (err error)
|
||||
WriteGroup(ctx context.Context, g *proto.Group) (err error)
|
||||
LoadGroup(ctx context.Context, id string, g *proto.Group) (err error)
|
||||
DeleteGroup(ctx context.Context, id string) (err error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user