ci: expand shared package validation and test coverage
- Add lint, formatting, vet, and publish workflow checks - Run Go database tests with PostgreSQL and add Java tests - Make consumer sync opt-in; update docs and Go dependency
This commit is contained in:
1 parent
937f51b4fb
commit
0ff94f9b10
107 files changed
+10124
-410
No files matched your search
@@ -457,6 +457,30 @@ func thumbnailFile(id string) (string, error) {
|
||||
return id + ".jpg", nil
|
||||
}
|
||||
|
||||
// validName reports an error unless name can be used as one path segment: it must not be empty,
|
||||
// ".", ".." or contain a path separator. Every push and delete helper checks its name with this.
|
||||
func validName(name string) error {
|
||||
if name == "" || name == "." || name == ".." || strings.ContainsAny(name, `/\`) {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validRelativeName is validName for outputs, inputs and copies, which may sit in nested
|
||||
// directories (for example CraftStudio's "<user>/<workflow>/<file>"). It refuses an empty or
|
||||
// absolute name, a backslash, and any empty, "." or ".." segment.
|
||||
func validRelativeName(name string) error {
|
||||
if name == "" || strings.HasPrefix(name, "/") || strings.ContainsRune(name, '\\') {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
for _, segment := range strings.Split(name, "/") {
|
||||
if segment == "" || segment == "." || segment == ".." {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// thumbnailPaths lists every CarrierNode path a thumbnail may live at, in lookup order: the
|
||||
// project's thumbnails mount first, then CarrierNode's legacy thumbnail root. Thumbnails
|
||||
// stored before the mount existed sit in the legacy root, and reads keep finding them there
|
||||
@@ -670,6 +694,9 @@ func pushedSize(response *http.Response) int64 {
|
||||
|
||||
// PushThumbnail uploads a locally-generated thumbnail to CarrierNode.
|
||||
func (c *Client) PushThumbnail(ctx context.Context, id, localPath string) (int64, error) {
|
||||
if err := validName(id); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/thumbnails/"+url.PathEscape(id), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -680,6 +707,9 @@ func (c *Client) PushThumbnail(ctx context.Context, id, localPath string) (int64
|
||||
// DeleteThumbnail removes a thumbnail from CarrierNode. A 404 is treated as
|
||||
// already-deleted, not an error. Always targets the primary instance.
|
||||
func (c *Client) DeleteThumbnail(ctx context.Context, id string) error {
|
||||
if err := validName(id); err != nil {
|
||||
return err
|
||||
}
|
||||
request, err := c.newRequest(ctx, c.primaryBaseURL(ctx), http.MethodDelete, "/api/thumbnails/"+url.PathEscape(id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -698,6 +728,9 @@ func (c *Client) DeleteThumbnail(ctx context.Context, id string) error {
|
||||
// PushOutput uploads a locally-produced output file (e.g. a converted or
|
||||
// generated media file) to CarrierNode's OutputRoot.
|
||||
func (c *Client) PushOutput(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/outputs/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -707,6 +740,9 @@ func (c *Client) PushOutput(ctx context.Context, name, localPath string) (int64,
|
||||
|
||||
// PushInput uploads a local file to CarrierNode's InputRoot.
|
||||
func (c *Client) PushInput(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/inputs/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -716,6 +752,9 @@ func (c *Client) PushInput(ctx context.Context, name, localPath string) (int64,
|
||||
|
||||
// PushCopy uploads a local file to CarrierNode's CopyRoot.
|
||||
func (c *Client) PushCopy(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/copies/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in new issue
Block a user