-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathresource.go
43 lines (34 loc) · 1.3 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package copy
import (
"github.com/jumppad-labs/hclconfig/types"
"github.com/jumppad-labs/jumppad/pkg/config"
"github.com/jumppad-labs/jumppad/pkg/utils"
)
// TypeCopy copies files from one location to another
const TypeCopy string = "copy"
// Docs allows the running of a Docusaurus container which can be used for
// online tutorials or documentation
type Copy struct {
// embedded type holding name, etc
types.ResourceMetadata `hcl:",remain"`
Depends []string `hcl:"depends_on,optional" json:"depends,omitempty"`
Source string `hcl:"source" json:"source"` // Source file, folder or glob
Destination string `hcl:"destination" json:"destination"` // Destination to write file or files to
Permissions string `hcl:"permissions,optional" json:"permissions,omitempty"` // Permissions 0777 to set for written file
// outputs
CopiedFiles []string `hcl:"copied_files,optional" json:"copied_files"`
}
func (t *Copy) Process() error {
t.Source = utils.EnsureAbsolute(t.Source, t.File)
t.Destination = utils.EnsureAbsolute(t.Destination, t.File)
cfg, err := config.LoadState()
if err == nil {
// try and find the resource in the state
r, _ := cfg.FindResource(t.ID)
if r != nil {
kstate := r.(*Copy)
t.CopiedFiles = kstate.CopiedFiles
}
}
return nil
}