-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (58 loc) · 1.2 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package concourse_tfe_resource
import (
"context"
tfe "github.com/hashicorp/go-tfe"
"io"
"log"
"os"
"path"
)
var client *tfe.Client
var workspace *tfe.Workspace
var workingDirectory string
func startup(input inputJSON) error {
config := &tfe.Config{
Token: input.Source.Token,
Address: input.Source.Address,
}
var err error
client, err = tfe.NewClient(config)
if err != nil {
return formatError(err, "creating tfe client")
}
workspace, err = client.Workspaces.Read(context.Background(),
input.Source.Organization,
input.Source.Workspace)
if err != nil {
return formatError(err, "getting workspace")
}
return nil
}
func realMain(args []string, stdin io.Reader) ([]byte, error) {
var output []byte
input, err := getInputs(stdin)
if err != nil {
return nil, err
}
if err := startup(input); err != nil {
return nil, err
}
switch path.Base(args[0]) {
case "check":
output, err = check(input)
case "in":
workingDirectory = args[1]
output, err = in(input)
case "out":
workingDirectory = args[1]
output, err = out(input)
}
return output, err
}
func main() {
output, err := realMain(os.Args, os.Stdin)
if err != nil {
log.Fatal(err)
}
_, _ = os.Stdout.Write(output)
}