github.com/octohelm/wagon@v0.0.0-20240308040401-88662650dc0b/pkg/engine/plan/task/http_fetch.go (about)

     1  package task
     2  
     3  import (
     4  	"dagger.io/dagger"
     5  	"github.com/octohelm/wagon/pkg/engine/daggerutil"
     6  	"github.com/octohelm/wagon/pkg/engine/plan/task/core"
     7  	"golang.org/x/net/context"
     8  )
     9  
    10  func init() {
    11  	core.DefaultFactory.Register(&HTTPFetch{})
    12  }
    13  
    14  type HTTPFetch struct {
    15  	core.Task
    16  
    17  	Source string `json:"source"`
    18  	Dest   string `json:"dest"`
    19  
    20  	Output core.FS `json:"-" wagon:"generated,name=output"`
    21  }
    22  
    23  func (input *HTTPFetch) Do(ctx context.Context) error {
    24  	return daggerutil.Do(ctx, func(c *dagger.Client) error {
    25  		dir := c.Directory().WithFile(input.Dest, c.HTTP(input.Source))
    26  		return input.Output.SetDirectoryIDBy(ctx, dir)
    27  	})
    28  }