This repository was archived by the owner on Jun 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathot_base.go
More file actions
116 lines (99 loc) · 2.45 KB
/
Copy pathot_base.go
File metadata and controls
116 lines (99 loc) · 2.45 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"bytes"
"fmt"
"io/fs"
"os"
"strings"
"gopkg.in/yaml.v3"
)
type fileSystem interface {
Stat(path string) (fs.FileInfo, error)
ReadFile(path string) ([]byte, error)
WriteFile(path string, b []byte, perm fs.FileMode) error
Remove(path string) error
Rename(oldPath, newPath string) error
MkdirAll(path string, perm fs.FileMode) error
}
type Fs struct{}
func newFs() fileSystem {
return Fs{}
}
func (f Fs) Stat(path string) (fs.FileInfo, error) {
return os.Stat(path)
}
func (f Fs) ReadFile(path string) ([]byte, error) {
return os.ReadFile(path)
}
func (f Fs) WriteFile(path string, b []byte, perm fs.FileMode) error {
return os.WriteFile(path, b, perm)
}
func (f Fs) Remove(path string) error {
return os.Remove(path)
}
func (f Fs) Rename(oldPath, newPath string) error {
return os.Rename(oldPath, newPath)
}
func (f Fs) MkdirAll(path string, perm fs.FileMode) error {
return os.MkdirAll(path, perm)
}
type workspaceObject struct {
Id int64
Name string
Description *string
IconUrl *string
WorkspaceId int64
ManagedById *int64
}
type folderObject struct {
FolderId int64
}
type auditedObject struct {
CreatedBy int64
CreatedDate string
UpdatedBy int64
UpdatedDate string
}
type InputObject struct {
Object map[string]any `yaml:"object"`
Params map[string]any `yaml:"params"`
}
func parseInput(fs fileSystem, op Output, flagInput string) (*InputObject, error) {
if flagInput == "" {
return nil, fmt.Errorf("No --definition provided")
}
var fileContentBytes []byte
isYamlFile := strings.HasSuffix(flagInput, ".yaml")
isJsonFile := strings.HasSuffix(flagInput, ".json")
if flagInput == "-" {
b, err := fs.ReadFile("/dev/stdin")
if err != nil {
return nil, err
}
fileContentBytes = []byte(b)
} else if isYamlFile || isJsonFile {
op.Debug("parseInput: parse as file\n")
if _, err := fs.Stat(flagInput); err != nil {
return nil, fmt.Errorf("Provided file does not exist at path:%s", flagInput)
}
if isYamlFile {
op.Debug("parseInput: file is yaml\n")
} else if isJsonFile {
op.Debug("parseInput: file is json\n")
}
var err error
fileContentBytes, err = fs.ReadFile(flagInput)
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("Failed to parse input --definition")
}
buf := bytes.NewBuffer(fileContentBytes)
dec := yaml.NewDecoder(buf)
var content InputObject
if err := dec.Decode(&content); err != nil {
return nil, err
}
return &content, nil
}