1
0
mirror of https://github.com/go-task/task.git synced 2024-12-16 10:59:23 +02:00
task/taskfile/read/node.go
Pete Davison 22ce67c5e5
feat: remote taskfiles (HTTP) (#1152)
* feat: remote taskfiles over http

* feat: allow insecure connections when --insecure flag is provided

* feat: better error handling for fetch errors

* fix: ensure cache directory always exists

* fix: setup logger before everything else

* feat: put remote taskfiles behind an experiment

* feat: --download and --offline flags for remote taskfiles

* feat: node.Read accepts a context

* feat: experiment docs

* chore: changelog

* chore: remove unused optional param from Node interface

* chore: tidy up and generalise NewNode function

* fix: use sha256 in remote checksum

* feat: --download by itself will not run a task

* feat: custom error if remote taskfiles experiment is not enabled

* refactor: BaseNode functional options and simplified FileNode

* fix: use hex encoding for checksum instead of b64
2023-09-12 22:42:54 +01:00

45 lines
962 B
Go

package read
import (
"context"
"strings"
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/experiments"
)
type Node interface {
Read(ctx context.Context) ([]byte, error)
Parent() Node
Location() string
Optional() bool
Remote() bool
}
func NewNode(
uri string,
insecure bool,
opts ...NodeOption,
) (Node, error) {
var node Node
var err error
switch getScheme(uri) {
case "http", "https":
node, err = NewHTTPNode(uri, insecure, opts...)
default:
// If no other scheme matches, we assume it's a file
node, err = NewFileNode(uri, opts...)
}
if node.Remote() && !experiments.RemoteTaskfiles {
return nil, errors.New("task: Remote taskfiles are not enabled. You can read more about this experiment and how to enable it at https://taskfile.dev/experiments/remote-taskfiles")
}
return node, err
}
func getScheme(uri string) string {
if i := strings.Index(uri, "://"); i != -1 {
return uri[:i]
}
return ""
}