-
Notifications
You must be signed in to change notification settings - Fork 4
/
hook.ts
113 lines (96 loc) · 2.73 KB
/
hook.ts
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
import { CloudFormationStack } from "../aws/cloudformation/model.js"
import { StacksContext } from "../context/stacks-context.js"
import { Stack } from "../stacks/stack.js"
import { StackOperationVariables } from "../takomo-stacks-context/model.js"
import { TkmLogger } from "../utils/logging.js"
export type HookType = string
export type HookName = string
/**
* Specifies during which stack operation the hook should be executed.
*/
export type HookOperation = "create" | "update" | "delete"
/**
* Specifies during which stack operation stage stage the hook should be executed.
*/
export type HookStage = "before" | "after"
/**
* Specifies after which stack operation status the hook should be executed.
*/
export type HookStatus = "success" | "failed" | "skipped" | "cancelled"
export type HookOutput = HookOutputObject | Error | boolean
export type HookExecutionResult = "continue" | "abort" | "skip"
export interface HooksExecutionOutput {
/**
* Message describing the outcome of the action.
*/
readonly message: string
/**
* Hook execution result.
*/
readonly result: HookExecutionResult
/**
* If an error was thrown during execution it will be stored here.
*/
readonly error?: Error
}
/**
* Input for a life-cycle hook action.
*/
export interface HookInput {
readonly ctx: StacksContext
readonly stack: Stack
readonly variables: StackOperationVariables
readonly stage: HookStage
readonly operation: HookOperation
readonly currentStack?: CloudFormationStack
readonly status?: HookStatus
readonly logger: TkmLogger
}
/**
* Output of a life-cycle hook action.
*/
export interface HookOutputObject {
/**
* Optional message describing the outcome of the action.
*/
readonly message?: string
/**
* Boolean describing if the action was successful.
*/
readonly success: boolean
/**
* Optional return value.
*/
readonly value?: any
/**
* Optional error.
*/
readonly error?: Error
/**
* Optional boolean that can be returned from hooks executed
* before the stack operation to indicate that the operation
* should be skipped and all the remaining before hooks should
* be ignored.
*/
readonly skip?: boolean
}
/**
* Life-cycle hook used to perform actions at different stages of stack deploy and undeploy commands.
*/
export interface Hook {
/**
* Perform the hook action.
*
* @param input Inputs for the action
* @returns Action output
*/
execute: (input: HookInput) => Promise<HookOutput>
}
export interface HookConfig {
readonly name: HookName
readonly type: HookType
readonly stage?: ReadonlyArray<HookStage>
readonly operation?: ReadonlyArray<HookOperation>
readonly status?: ReadonlyArray<HookStatus>
[property: string]: unknown
}