Skip to content

Commit

Permalink
add webapp template
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Mar 1, 2023
1 parent 7d05a4c commit f1acdfc
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions internal/grpc/services/ocmshareprovider/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"fmt"
"net/url"
"path/filepath"
"strings"
"text/template"
"time"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
Expand Down Expand Up @@ -59,13 +61,15 @@ type config struct {
ClientInsecure bool `mapstructure:"client_insecure"`
GatewaySVC string `mapstructure:"gatewaysvc"`
WebDAVPrefix string `mapstructure:"webdav_prefix"`
WebappTemplate string `mapstructure:"webapp_template"`
}

type service struct {
conf *config
repo share.Repository
client *client.OCMClient
gateway gateway.GatewayAPIClient
conf *config
repo share.Repository
client *client.OCMClient
gateway gateway.GatewayAPIClient
webappTmpl *template.Template
}

func (c *config) init() {
Expand All @@ -75,6 +79,9 @@ func (c *config) init() {
if c.ClientTimeout == 0 {
c.ClientTimeout = 10
}
if c.WebappTemplate == "" {
c.WebappTemplate = "https://cernbox.cern.ch/external/sciencemesh/{{.Token}}{relative-path-to-shared-resource}"
}

c.GatewaySVC = sharedconf.GetGatewaySVC(c.GatewaySVC)
}
Expand Down Expand Up @@ -122,11 +129,17 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
return nil, err
}

tpl, err := template.New("webapp_template").Parse(c.WebappTemplate)
if err != nil {
return nil, err
}

service := &service{
conf: c,
repo: repo,
client: client,
gateway: gateway,
conf: c,
repo: repo,
client: client,
gateway: gateway,
webappTmpl: tpl,
}

return service, nil
Expand Down Expand Up @@ -189,14 +202,24 @@ func (s *service) getWebdavProtocol(ctx context.Context, info *providerpb.Resour
}
}

func (s *service) getProtocols(ctx context.Context, info *providerpb.ResourceInfo, methods []*ocm.AccessMethod) ocmd.Protocols {
func (s *service) getWebappProtocol(share *ocm.Share) *ocmd.Webapp {
var b strings.Builder
if err := s.webappTmpl.Execute(&b, share); err != nil {
panic(err)
}
return &ocmd.Webapp{
URITemplate: b.String(),
}
}

func (s *service) getProtocols(ctx context.Context, share *ocm.Share, info *providerpb.ResourceInfo, methods []*ocm.AccessMethod) ocmd.Protocols {
var p ocmd.Protocols
for _, m := range methods {
switch t := m.Term.(type) {
case *ocm.AccessMethod_WebdavOptions:
p = append(p, s.getWebdavProtocol(ctx, info, t))
case *ocm.AccessMethod_WebappOptions:
// TODO
p = append(p, s.getWebappProtocol(share))
case *ocm.AccessMethod_TransferOptions:
// TODO
}
Expand Down Expand Up @@ -278,7 +301,7 @@ func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareReq
SenderDisplayName: user.DisplayName,
ShareType: "user",
ResourceType: getResourceType(info),
Protocols: s.getProtocols(ctx, info, req.AccessMethods),
Protocols: s.getProtocols(ctx, ocmshare, info, req.AccessMethods),
}

if req.Expiration != nil {
Expand Down

0 comments on commit f1acdfc

Please sign in to comment.