Skip to content

Commit

Permalink
Implement new lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Veld committed Aug 15, 2023
1 parent bcdd2ee commit a9d76b4
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 138 deletions.
10 changes: 3 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"--grpc-bind=:30001",
"--http-bind=:30002",
"--api-bind=:30003",
"--root-cert-path=~/.jumppad/certs/root.cert",
"--server-cert-path=~/.jumppad/certs/leaf.cert",
"--server-key-path=~/.jumppad/certs/leaf.key",
"--root-cert-path=${env:HOME}/.jumppad/certs/root.cert",
"--server-cert-path=${env:HOME}/.jumppad/certs/leaf.cert",
"--server-key-path=${env:HOME}/.jumppad/certs/leaf.key",
"--log-level=debug"
]
},
Expand All @@ -38,7 +38,6 @@
"up",
"${input:blueprint}",
],
"runOptions": { "reevaluateOnRerun": false}
},
{
"name": "Debug - Up2",
Expand All @@ -53,7 +52,6 @@
"up",
"../terraform-workshop",
],
"runOptions": { "reevaluateOnRerun": false}
},
{
"name": "Debug - Dev",
Expand All @@ -68,7 +66,6 @@
"dev",
"${input:blueprint}",
],
"runOptions": { "reevaluateOnRerun": false}
},
{
"name": "Debug - Down",
Expand Down Expand Up @@ -111,7 +108,6 @@
"test",
"${input:blueprint}",
],
"runOptions": { "reevaluateOnRerun": false}
}
],
"inputs": [
Expand Down
46 changes: 0 additions & 46 deletions pkg/config/resources/docs/provider_task.go

This file was deleted.

112 changes: 102 additions & 10 deletions pkg/config/resources/docs/resource_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,112 @@ type Task struct {
}

type Condition struct {
Name string `hcl:"id,label" json:"id"`
Description string `hcl:"description" json:"description"`
Check string `hcl:"check" json:"check"`
Solve string `hcl:"solve,optional" json:"solve,omitempty"`
FailureMessage string `hcl:"failure_message" json:"failure_message,omitempty"`
SuccessMessage string `hcl:"success_message,optional" json:"success_message,omitempty"`
Target string `hcl:"target,optional" json:"target,omitempty"`
User string `hcl:"user,optional" json:"user,omitempty"`
WorkingDirectory string `hcl:"working_directory,optional" json:"working_directory,omitempty"`
Status string `hcl:"status,optional" json:"status"`
Name string `hcl:"id,label" json:"id"`
Description string `hcl:"description" json:"description"`
Checks []Validation `hcl:"check,block" json:"checks"`
Solves []Validation `hcl:"solve,block" json:"solves,omitempty"`
Setups []Validation `hcl:"setup,block" json:"setups,omitempty"`
Cleanups []Validation `hcl:"cleanup,block" json:"cleanups,omitempty"`
Status string `hcl:"status,optional" json:"status"`
}

type Validation struct {
Script string `hcl:"script" json:"script"`
FailureMessage string `hcl:"failure_message,optional" json:"failure_message,omitempty"`
SuccessMessage string `hcl:"success_message,optional" json:"success_message,omitempty"`
Config `hcl:",remain"`
}

type Config struct {
Timeout int `hcl:"timeout,optional" json:"timeout"`
Target string `hcl:"target,optional" json:"target,omitempty"`
User string `hcl:"user,optional" json:"user,omitempty"`
Group string `hcl:"group,optional" json:"group,omitempty"`
WorkingDirectory string `hcl:"working_directory,optional" json:"working_directory,omitempty"`
}

func (t *Task) Process() error {
// Set defaults
if t.Config.Timeout == 0 {
t.Config.Timeout = 30
}

if t.Config.User == "" {
t.Config.User = "root"
}

if t.Config.WorkingDirectory == "" {
t.Config.WorkingDirectory = "/"
}

// set overrides
for i, condition := range t.Conditions {
for j, check := range condition.Checks {
if check.Timeout == 0 {
t.Conditions[i].Checks[j].Timeout = t.Config.Timeout
}

if check.Target == "" {
t.Conditions[i].Checks[j].Target = t.Config.Target
}

if check.User == "" {
t.Conditions[i].Checks[j].User = t.Config.User
}

if check.Group == "" {
t.Conditions[i].Checks[j].Group = t.Config.Group
}

if check.WorkingDirectory == "" {
t.Conditions[i].Checks[j].WorkingDirectory = t.Config.WorkingDirectory
}
}

for j, solve := range condition.Solves {
if solve.Timeout == 0 {
t.Conditions[i].Solves[j].Timeout = t.Config.Timeout
}

if solve.Target == "" {
t.Conditions[i].Solves[j].Target = t.Config.Target
}

if solve.User == "" {
t.Conditions[i].Solves[j].User = t.Config.User
}

if solve.Group == "" {
t.Conditions[i].Solves[j].Group = t.Config.Group
}

if solve.WorkingDirectory == "" {
t.Conditions[i].Solves[j].WorkingDirectory = t.Config.WorkingDirectory
}
}

for j, setup := range condition.Setups {
if setup.Timeout == 0 {
t.Conditions[i].Setups[j].Timeout = t.Config.Timeout
}

if setup.Target == "" {
t.Conditions[i].Setups[j].Target = t.Config.Target
}

if setup.User == "" {
t.Conditions[i].Setups[j].User = t.Config.User
}

if setup.Group == "" {
t.Conditions[i].Setups[j].Group = t.Config.Group
}

if setup.WorkingDirectory == "" {
t.Conditions[i].Setups[j].WorkingDirectory = t.Config.WorkingDirectory
}
}
}

return nil
}
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func New(addr string, l logger.Logger) *API {
}

router.Get("/terminal", api.terminal)
router.Post("/validate", api.validation)
router.Post("/validate/{task}/{action}", api.validation)

return api
}
Expand Down
Loading

0 comments on commit a9d76b4

Please sign in to comment.