This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
/
runner_profile_inspect.go
161 lines (139 loc) · 3.84 KB
/
runner_profile_inspect.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package cli
import (
"encoding/json"
"fmt"
"github.com/posener/complete"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
"github.com/hashicorp/waypoint/internal/clierrors"
"github.com/hashicorp/waypoint/internal/pkg/flag"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
)
type RunnerProfileInspectCommand struct {
*baseCommand
flagJson bool
}
func (c *RunnerProfileInspectCommand) Run(args []string) int {
// Initialize. If we fail, we just exit since Init handles the UI.
if err := c.Init(
WithArgs(args),
WithFlags(c.Flags()),
WithNoLocalServer(), // no auth in local mode
WithNoConfig(),
); err != nil {
return 1
}
if len(c.args) == 0 {
c.ui.Output("Runner profile name required.", terminal.WithErrorStyle())
return 1
}
name := c.args[0]
resp, err := c.project.Client().GetOnDemandRunnerConfig(c.Ctx, &pb.GetOnDemandRunnerConfigRequest{
Config: &pb.Ref_OnDemandRunnerConfig{
Name: name,
},
})
if err != nil && status.Code(err) != codes.NotFound {
c.ui.Output(clierrors.Humanize(err), terminal.WithErrorStyle())
return 1
}
// Try again with arg as the ID
if resp == nil {
resp, err = c.project.Client().GetOnDemandRunnerConfig(c.Ctx, &pb.GetOnDemandRunnerConfigRequest{
Config: &pb.Ref_OnDemandRunnerConfig{
Id: name,
},
})
if err != nil {
if status.Code(err) != codes.NotFound {
c.ui.Output("runner profile not found", terminal.WithErrorStyle())
return 1
}
c.ui.Output(clierrors.Humanize(err), terminal.WithErrorStyle())
return 1
}
}
config := resp.Config
if c.flagJson {
data, err := protojson.MarshalOptions{
Indent: "\t",
}.Marshal(config)
if err != nil {
c.ui.Output(clierrors.Humanize(err), terminal.WithErrorStyle())
return 1
}
fmt.Println(string(data))
return 0
}
var targetRunner string
if config.TargetRunner != nil {
switch t := config.TargetRunner.Target.(type) {
case *pb.Ref_Runner_Any:
targetRunner = "*"
case *pb.Ref_Runner_Id:
targetRunner = t.Id.Id
case *pb.Ref_Runner_Labels:
s, _ := json.Marshal(t.Labels.Labels)
targetRunner = "labels: " + string(s)
}
}
c.ui.Output("Runner profile:", terminal.WithHeaderStyle())
c.ui.NamedValues([]terminal.NamedValue{
{
Name: "Name", Value: config.Name,
},
{
Name: "ID", Value: config.Id,
},
{
Name: "Default", Value: config.Default,
},
{
Name: "OCI URL", Value: config.OciUrl,
},
{
Name: "Plugin Type", Value: config.PluginType,
},
{
Name: "Target Runner", Value: targetRunner,
},
{
Name: "Environment Variables", Value: config.EnvironmentVariables,
},
}, terminal.WithInfoStyle())
if len(config.PluginConfig) > 0 {
c.ui.Output("Additional Plugin Configuration:", terminal.WithHeaderStyle())
// We have to do the %s here in case the plugin config contains
// formatting chars we don't want to error.
c.ui.Output("\n%s", string(config.PluginConfig))
}
return 0
}
func (c *RunnerProfileInspectCommand) Flags() *flag.Sets {
return c.flagSet(0, func(sets *flag.Sets) {
f := sets.NewSet("Command Options")
f.BoolVar(&flag.BoolVar{
Name: "json",
Target: &c.flagJson,
Usage: "Output runner profile information as JSON. This includes " +
"more fields since this is the complete API structure.",
})
})
}
func (c *RunnerProfileInspectCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *RunnerProfileInspectCommand) AutocompleteFlags() complete.Flags {
return c.Flags().Completions()
}
func (c *RunnerProfileInspectCommand) Synopsis() string {
return "Show detailed information about a runner profile."
}
func (c *RunnerProfileInspectCommand) Help() string {
return formatHelp(`
Usage: waypoint runner profile inspect <name>
Show detailed information about a runner profile.
`)
}