As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 324797e8 authored by Patrick Bajao's avatar Patrick Bajao
Browse files

Refactor GitlabBackend methods to match updated interface

parent e4638284
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"time"
"github.com/charmbracelet/git-lfs-transfer/transfer"
Loading
Loading
@@ -213,34 +212,24 @@ func (b *GitlabBackend) parseAndCheckBatchArgs(op, oid, id, token string) (href
return idData.Href, idData.Headers, nil
}
type uploadCloser struct{}
func (c *uploadCloser) Close() error {
return nil
}
func (b *GitlabBackend) StartUpload(oid string, r io.Reader, args transfer.Args) (io.Closer, error) {
func (b *GitlabBackend) Upload(oid string, _ int64, r io.Reader, args transfer.Args) error {
href, headers, err := b.parseAndCheckBatchArgs("upload", oid, args["id"], args["token"])
if err != nil {
_, _ = io.Copy(io.Discard, r)
return nil, err
return err
}
return &uploadCloser{}, b.client.PutObject(oid, href, headers, r)
return b.client.PutObject(oid, href, headers, r)
}
func (b *GitlabBackend) FinishUpload(_ io.Closer, _ transfer.Args) error {
return nil
}
func (b *GitlabBackend) Verify(_ string, _ transfer.Args) (transfer.Status, error) {
func (b *GitlabBackend) Verify(_ string, _ int64, _ transfer.Args) (transfer.Status, error) {
// Not needed, all verification is done in upload step.
return transfer.SuccessStatus(), nil
}
func (b *GitlabBackend) Download(oid string, args transfer.Args) (fs.File, error) {
func (b *GitlabBackend) Download(oid string, args transfer.Args) (io.ReadCloser, int64, error) {
href, headers, err := b.parseAndCheckBatchArgs("download", oid, args["id"], args["token"])
if err != nil {
return nil, err
return nil, 0, err
}
return b.client.GetObject(oid, href, headers)
}
Loading
Loading
Loading
Loading
@@ -55,52 +55,6 @@ type BatchResponse struct {
HashAlgorithm string `json:"hash_algo,omitempty"`
}
type downloadedFileInfo struct {
oid string
size int64
reader io.ReadCloser
}
func (i *downloadedFileInfo) Name() string {
return i.oid
}
func (i *downloadedFileInfo) Size() int64 {
return i.size
}
func (i *downloadedFileInfo) Mode() fs.FileMode {
return 0
}
func (i *downloadedFileInfo) ModTime() time.Time {
return time.Time{}
}
func (i *downloadedFileInfo) IsDir() bool {
return false
}
func (i *downloadedFileInfo) Sys() any {
return i.reader
}
type downloadedFile struct {
downloadedFileInfo
}
func (f *downloadedFile) Read(buf []byte) (int, error) {
return f.downloadedFileInfo.reader.Read(buf)
}
func (f *downloadedFile) Close() error {
return f.downloadedFileInfo.reader.Close()
}
func (f *downloadedFile) Stat() (fs.FileInfo, error) {
return &f.downloadedFileInfo, nil
}
type lockRequest struct {
Path string `json:"path"`
Ref *batchRef `json:"ref,omitempty"`
Loading
Loading
@@ -214,7 +168,7 @@ func (c *Client) Batch(operation string, reqObjects []*BatchObject, ref string,
return response, nil
}
func (c *Client) GetObject(oid, href string, headers map[string]string) (fs.File, error) {
func (c *Client) GetObject(oid, href string, headers map[string]string) (io.ReadCloser, int64, error) {
req, _ := newHTTPRequest(http.MethodGet, href, nil)
for key, value := range headers {
req.Header.Add(key, value)
Loading
Loading
@@ -225,19 +179,13 @@ func (c *Client) GetObject(oid, href string, headers map[string]string) (fs.File
// discussion on bypassing the linter
res, err := client.Do(req) // nolint:bodyclose
if err != nil {
return nil, err
return nil, 0, err
}
if res.StatusCode < 200 || res.StatusCode > 299 {
return nil, fs.ErrNotExist
return nil, 0, fs.ErrNotExist
}
return &downloadedFile{
downloadedFileInfo{
oid: oid,
size: res.ContentLength,
reader: res.Body,
},
}, nil
return res.Body, res.ContentLength, nil
}
func (c *Client) PutObject(oid, href string, headers map[string]string, r io.Reader) error {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment