Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Sep 23, 2021
1 parent 3b2879b commit bd5cef8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
42 changes: 4 additions & 38 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,15 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
errtypes.UserRequired("Missing filename"))
return
}
// stat the container
_, ocmderr, err := statRef(ctx, provider.Reference{Path: r.URL.Query().Get("container")}, client)
if err != nil {
log.Error().Err(err).Msg("error statting container")
ocmd.WriteError(w, r, ocmderr, "Container not found", errtypes.NotFound("Container not found"))
return
}
// Create empty file via storageprovider: obtain the HTTP URL for a PUT
target = path.Join(r.URL.Query().Get("container"), target)

// Create empty file via storageprovider
createReq := &provider.InitiateFileUploadRequest{
Ref: &provider.Reference{Path: target},
Opaque: &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{
"Upload-Length": {
Decoder: "plain",
Value: []byte(strconv.FormatInt(0, 10)),
Value: []byte("0"),
},
},
},
Expand All @@ -168,34 +161,6 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

// Do a HTTP PUT with an empty body
var ep, token string
for _, p := range createRes.Protocols {
if p.Protocol == "simple" {
ep, token = p.UploadEndpoint, p.Token
}
}
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, nil)
if err != nil {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT", err)
return
}

httpReq.Header.Set(datagateway.TokenTransportHeader, token)
httpRes, err := rhttp.GetHTTPClient().Do(httpReq)
if err != nil {
log.Error().Err(err).Msg("error doing PUT request to data service")
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT", err)
return
}
defer httpRes.Body.Close()
if httpRes.StatusCode != http.StatusOK {
log.Error().Msg("PUT request to data server failed")
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT",
errtypes.InternalError(fmt.Sprint(httpRes.StatusCode)))
return
}

// Stat created file and return its file id
statRes, ocmderr, err := statRef(ctx, provider.Reference{Path: target}, client)
if err != nil {
Expand Down Expand Up @@ -307,6 +272,7 @@ func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent stri
}
}
if len(apps) > 0 {
m.AppProviders = apps
res = append(res, m)
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,19 @@ func (b *reg) ListSupportedMimeTypes(ctx context.Context) ([]*registrypb.MimeTyp
mtmap[m].AppProviders = append(mtmap[m].AppProviders, &t)
} else {
mtmap[m] = &registrypb.MimeTypeInfo{
MimeType: m,
AppProviders: []*registrypb.ProviderInfo{&t},
Ext: "", // TODO fetch from config
Name: "",
Description: "",
Icon: "",
}
res = append(res, mtmap[m])
}
}
}
for _, m := range mtmap {
res = append(res, m)
}
return res, nil
}

Expand Down

0 comments on commit bd5cef8

Please sign in to comment.