@suss/contract-terraform 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -3
- package/dist/index.cjs +541 -34
- package/dist/index.d.cts +122 -5
- package/dist/index.d.ts +122 -5
- package/dist/index.js +538 -34
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageBusTechnology, BehavioralSummary } from '@suss/behavioral-ir';
|
|
1
|
+
import { MessageBusTechnology, MetricValueShape, MetricAccumulation, BehavioralSummary } from '@suss/behavioral-ir';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What a pack says about the resources one Terraform provider declares.
|
|
@@ -55,7 +55,63 @@ interface MessageBusResource {
|
|
|
55
55
|
messageBus: MessageBusTechnology;
|
|
56
56
|
nameAttribute?: string;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* An attribute whose value the pack translates into one of suss's own
|
|
60
|
+
* words. The reader takes the value at `attribute` and looks it up in
|
|
61
|
+
* `means`; a value the pack did not list says nothing, the same as an
|
|
62
|
+
* attribute the configuration never set.
|
|
63
|
+
*/
|
|
64
|
+
interface AttributeMeaning<T extends string> {
|
|
65
|
+
/** The attribute path whose value says which one it is. */
|
|
66
|
+
attribute: string;
|
|
67
|
+
/** What each value the provider can write there means. */
|
|
68
|
+
means: Record<string, T>;
|
|
69
|
+
}
|
|
70
|
+
/** A named series of measurements a resource declares. */
|
|
71
|
+
interface MetricResource {
|
|
72
|
+
kind: "metric";
|
|
73
|
+
/** Which system the series lives in: cloud-monitoring. */
|
|
74
|
+
metricSystem: string;
|
|
75
|
+
/** The attribute that says what the metric is called. */
|
|
76
|
+
nameAttribute: string;
|
|
77
|
+
/**
|
|
78
|
+
* How the deployed metric type is spelled, with `{name}` standing
|
|
79
|
+
* for the declared name. That string is what a resource reading the
|
|
80
|
+
* metric spells, so it is the identity the two sides share.
|
|
81
|
+
*/
|
|
82
|
+
metricTypeTemplate: string;
|
|
83
|
+
/** Which attribute says whether one measurement is a number or a spread. */
|
|
84
|
+
values?: AttributeMeaning<MetricValueShape>;
|
|
85
|
+
/** Which attribute says what a measurement covers. */
|
|
86
|
+
accumulates?: AttributeMeaning<MetricAccumulation>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A resource that reads a metric another resource declares. One
|
|
90
|
+
* resource usually states several readings, each in its own block and
|
|
91
|
+
* each about its own metric, so each becomes a boundary of its own.
|
|
92
|
+
*/
|
|
93
|
+
interface MetricReadingResource {
|
|
94
|
+
kind: "metric-reading";
|
|
95
|
+
metricSystem: string;
|
|
96
|
+
/** The blocks one reading is written inside, outermost first. */
|
|
97
|
+
readingBlocks: string[];
|
|
98
|
+
/** The attribute whose query says which metric the reading is about. */
|
|
99
|
+
queryAttribute: string;
|
|
100
|
+
/** The key inside that query whose value is the metric's type. */
|
|
101
|
+
queryIdentityKey: string;
|
|
102
|
+
/**
|
|
103
|
+
* The attribute whose presence means the reading compares the series
|
|
104
|
+
* against a value of this shape. A condition states a threshold, so
|
|
105
|
+
* the number it compares against is the attribute being set at all.
|
|
106
|
+
*/
|
|
107
|
+
comparesTo?: {
|
|
108
|
+
attribute: string;
|
|
109
|
+
whenSet: MetricValueShape;
|
|
110
|
+
};
|
|
111
|
+
/** Which attribute says what the reading reduces each window to first. */
|
|
112
|
+
reducesTo?: AttributeMeaning<MetricValueShape>;
|
|
113
|
+
}
|
|
114
|
+
type TerraformResource = StorageResource | MessageBusResource | MetricResource | MetricReadingResource;
|
|
59
115
|
/** One resource type, as one version range of one provider declares it. */
|
|
60
116
|
interface TerraformResourcePattern {
|
|
61
117
|
/** The resource type, spelled the way the provider spells it. */
|
|
@@ -81,6 +137,65 @@ interface TerraformPack {
|
|
|
81
137
|
resources: TerraformResourcePattern[];
|
|
82
138
|
}
|
|
83
139
|
|
|
140
|
+
/**
|
|
141
|
+
* A filter written as comparisons joined by AND and OR.
|
|
142
|
+
*
|
|
143
|
+
* Several cloud APIs take a selector as one string in this shape:
|
|
144
|
+
* `metric.type = "x" AND resource.type = "y"`, with quoted or bare
|
|
145
|
+
* values, parentheses, NOT, and terms written next to each other for
|
|
146
|
+
* AND. A resource that reads what another resource declares usually
|
|
147
|
+
* says which one inside such a string, so reading the string is how
|
|
148
|
+
* this reader finds out what a resource refers to.
|
|
149
|
+
*
|
|
150
|
+
* A pack says which key it wants. This file knows the grammar and no
|
|
151
|
+
* provider's key names. What comes back is a tree, since OR and NOT
|
|
152
|
+
* change what a term claims and only the caller can judge that.
|
|
153
|
+
*/
|
|
154
|
+
/** One comparison, as the filter writes it. */
|
|
155
|
+
interface FilterTerm {
|
|
156
|
+
type: "term";
|
|
157
|
+
/**
|
|
158
|
+
* The left side, a dotted path such as `metric.type`. A segment the
|
|
159
|
+
* filter quotes, `metric.label."response_code"`, comes back without
|
|
160
|
+
* the quotes, so one key has one spelling.
|
|
161
|
+
*/
|
|
162
|
+
key: string;
|
|
163
|
+
/** `=`, `!=`, `>`, `>=`, `<`, `<=`, or `:` for "has". */
|
|
164
|
+
operator: string;
|
|
165
|
+
/** The right side, with the quotes taken off a quoted value. */
|
|
166
|
+
value: string;
|
|
167
|
+
}
|
|
168
|
+
/** A call standing where a comparison would, with its arguments. */
|
|
169
|
+
interface FilterCall {
|
|
170
|
+
type: "call";
|
|
171
|
+
name: string;
|
|
172
|
+
arguments: string[];
|
|
173
|
+
}
|
|
174
|
+
type FilterQuery = FilterTerm | FilterCall | {
|
|
175
|
+
type: "junction";
|
|
176
|
+
operator: "and" | "or";
|
|
177
|
+
operands: FilterQuery[];
|
|
178
|
+
} | {
|
|
179
|
+
type: "negation";
|
|
180
|
+
operand: FilterQuery;
|
|
181
|
+
};
|
|
182
|
+
/** A filter nobody could read says why, rather than reading as empty. */
|
|
183
|
+
type FilterParse = {
|
|
184
|
+
ok: true;
|
|
185
|
+
query: FilterQuery;
|
|
186
|
+
} | {
|
|
187
|
+
ok: false;
|
|
188
|
+
reason: string;
|
|
189
|
+
};
|
|
190
|
+
/** Every value a key is compared to with `=`, anywhere in the tree. */
|
|
191
|
+
declare function filterValuesFor(query: FilterQuery, key: string): string[];
|
|
192
|
+
/** Every comparison in the tree, in the order the filter writes them. */
|
|
193
|
+
declare function filterTerms(query: FilterQuery): FilterTerm[];
|
|
194
|
+
/** Every call in the tree, for a caller that reads one of them. */
|
|
195
|
+
declare function filterCalls(query: FilterQuery): FilterCall[];
|
|
196
|
+
/** Read one filter string, or say what stopped the reading. */
|
|
197
|
+
declare function parseFilterQuery(source: string): FilterParse;
|
|
198
|
+
|
|
84
199
|
/**
|
|
85
200
|
* The boundaries a Terraform configuration declares.
|
|
86
201
|
*
|
|
@@ -91,8 +206,10 @@ interface TerraformPack {
|
|
|
91
206
|
* A name is usually built at deploy time, and Terraform interpolates
|
|
92
207
|
* the same way CloudFormation does, so `"${local.environment}-orders"`
|
|
93
208
|
* becomes the pattern `{local.environment}-orders` and pairs with code
|
|
94
|
-
* that builds the same name from its own variable.
|
|
95
|
-
*
|
|
209
|
+
* that builds the same name from its own variable. An interpolation
|
|
210
|
+
* that refers to another resource in the same configuration resolves
|
|
211
|
+
* instead, since that resource states the value. The README says how a
|
|
212
|
+
* block that HCL states once or many times is read.
|
|
96
213
|
*/
|
|
97
214
|
|
|
98
215
|
interface TerraformReadOptions {
|
|
@@ -104,4 +221,4 @@ declare function terraformToSummaries(source: string, sourceFile: string, option
|
|
|
104
221
|
/** Read one `.tf` file, or every one directly inside a directory. */
|
|
105
222
|
declare function terraformFileToSummaries(target: string, options: TerraformReadOptions): BehavioralSummary[];
|
|
106
223
|
|
|
107
|
-
export { type MessageBusResource, type StorageResource, type TerraformPack, type TerraformReadOptions, type TerraformResource, type TerraformResourcePattern, terraformFileToSummaries, terraformToSummaries };
|
|
224
|
+
export { type AttributeMeaning, type FilterCall, type FilterParse, type FilterQuery, type FilterTerm, type MessageBusResource, type MetricReadingResource, type MetricResource, type StorageResource, type TerraformPack, type TerraformReadOptions, type TerraformResource, type TerraformResourcePattern, filterCalls, filterTerms, filterValuesFor, parseFilterQuery, terraformFileToSummaries, terraformToSummaries };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageBusTechnology, BehavioralSummary } from '@suss/behavioral-ir';
|
|
1
|
+
import { MessageBusTechnology, MetricValueShape, MetricAccumulation, BehavioralSummary } from '@suss/behavioral-ir';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What a pack says about the resources one Terraform provider declares.
|
|
@@ -55,7 +55,63 @@ interface MessageBusResource {
|
|
|
55
55
|
messageBus: MessageBusTechnology;
|
|
56
56
|
nameAttribute?: string;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* An attribute whose value the pack translates into one of suss's own
|
|
60
|
+
* words. The reader takes the value at `attribute` and looks it up in
|
|
61
|
+
* `means`; a value the pack did not list says nothing, the same as an
|
|
62
|
+
* attribute the configuration never set.
|
|
63
|
+
*/
|
|
64
|
+
interface AttributeMeaning<T extends string> {
|
|
65
|
+
/** The attribute path whose value says which one it is. */
|
|
66
|
+
attribute: string;
|
|
67
|
+
/** What each value the provider can write there means. */
|
|
68
|
+
means: Record<string, T>;
|
|
69
|
+
}
|
|
70
|
+
/** A named series of measurements a resource declares. */
|
|
71
|
+
interface MetricResource {
|
|
72
|
+
kind: "metric";
|
|
73
|
+
/** Which system the series lives in: cloud-monitoring. */
|
|
74
|
+
metricSystem: string;
|
|
75
|
+
/** The attribute that says what the metric is called. */
|
|
76
|
+
nameAttribute: string;
|
|
77
|
+
/**
|
|
78
|
+
* How the deployed metric type is spelled, with `{name}` standing
|
|
79
|
+
* for the declared name. That string is what a resource reading the
|
|
80
|
+
* metric spells, so it is the identity the two sides share.
|
|
81
|
+
*/
|
|
82
|
+
metricTypeTemplate: string;
|
|
83
|
+
/** Which attribute says whether one measurement is a number or a spread. */
|
|
84
|
+
values?: AttributeMeaning<MetricValueShape>;
|
|
85
|
+
/** Which attribute says what a measurement covers. */
|
|
86
|
+
accumulates?: AttributeMeaning<MetricAccumulation>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A resource that reads a metric another resource declares. One
|
|
90
|
+
* resource usually states several readings, each in its own block and
|
|
91
|
+
* each about its own metric, so each becomes a boundary of its own.
|
|
92
|
+
*/
|
|
93
|
+
interface MetricReadingResource {
|
|
94
|
+
kind: "metric-reading";
|
|
95
|
+
metricSystem: string;
|
|
96
|
+
/** The blocks one reading is written inside, outermost first. */
|
|
97
|
+
readingBlocks: string[];
|
|
98
|
+
/** The attribute whose query says which metric the reading is about. */
|
|
99
|
+
queryAttribute: string;
|
|
100
|
+
/** The key inside that query whose value is the metric's type. */
|
|
101
|
+
queryIdentityKey: string;
|
|
102
|
+
/**
|
|
103
|
+
* The attribute whose presence means the reading compares the series
|
|
104
|
+
* against a value of this shape. A condition states a threshold, so
|
|
105
|
+
* the number it compares against is the attribute being set at all.
|
|
106
|
+
*/
|
|
107
|
+
comparesTo?: {
|
|
108
|
+
attribute: string;
|
|
109
|
+
whenSet: MetricValueShape;
|
|
110
|
+
};
|
|
111
|
+
/** Which attribute says what the reading reduces each window to first. */
|
|
112
|
+
reducesTo?: AttributeMeaning<MetricValueShape>;
|
|
113
|
+
}
|
|
114
|
+
type TerraformResource = StorageResource | MessageBusResource | MetricResource | MetricReadingResource;
|
|
59
115
|
/** One resource type, as one version range of one provider declares it. */
|
|
60
116
|
interface TerraformResourcePattern {
|
|
61
117
|
/** The resource type, spelled the way the provider spells it. */
|
|
@@ -81,6 +137,65 @@ interface TerraformPack {
|
|
|
81
137
|
resources: TerraformResourcePattern[];
|
|
82
138
|
}
|
|
83
139
|
|
|
140
|
+
/**
|
|
141
|
+
* A filter written as comparisons joined by AND and OR.
|
|
142
|
+
*
|
|
143
|
+
* Several cloud APIs take a selector as one string in this shape:
|
|
144
|
+
* `metric.type = "x" AND resource.type = "y"`, with quoted or bare
|
|
145
|
+
* values, parentheses, NOT, and terms written next to each other for
|
|
146
|
+
* AND. A resource that reads what another resource declares usually
|
|
147
|
+
* says which one inside such a string, so reading the string is how
|
|
148
|
+
* this reader finds out what a resource refers to.
|
|
149
|
+
*
|
|
150
|
+
* A pack says which key it wants. This file knows the grammar and no
|
|
151
|
+
* provider's key names. What comes back is a tree, since OR and NOT
|
|
152
|
+
* change what a term claims and only the caller can judge that.
|
|
153
|
+
*/
|
|
154
|
+
/** One comparison, as the filter writes it. */
|
|
155
|
+
interface FilterTerm {
|
|
156
|
+
type: "term";
|
|
157
|
+
/**
|
|
158
|
+
* The left side, a dotted path such as `metric.type`. A segment the
|
|
159
|
+
* filter quotes, `metric.label."response_code"`, comes back without
|
|
160
|
+
* the quotes, so one key has one spelling.
|
|
161
|
+
*/
|
|
162
|
+
key: string;
|
|
163
|
+
/** `=`, `!=`, `>`, `>=`, `<`, `<=`, or `:` for "has". */
|
|
164
|
+
operator: string;
|
|
165
|
+
/** The right side, with the quotes taken off a quoted value. */
|
|
166
|
+
value: string;
|
|
167
|
+
}
|
|
168
|
+
/** A call standing where a comparison would, with its arguments. */
|
|
169
|
+
interface FilterCall {
|
|
170
|
+
type: "call";
|
|
171
|
+
name: string;
|
|
172
|
+
arguments: string[];
|
|
173
|
+
}
|
|
174
|
+
type FilterQuery = FilterTerm | FilterCall | {
|
|
175
|
+
type: "junction";
|
|
176
|
+
operator: "and" | "or";
|
|
177
|
+
operands: FilterQuery[];
|
|
178
|
+
} | {
|
|
179
|
+
type: "negation";
|
|
180
|
+
operand: FilterQuery;
|
|
181
|
+
};
|
|
182
|
+
/** A filter nobody could read says why, rather than reading as empty. */
|
|
183
|
+
type FilterParse = {
|
|
184
|
+
ok: true;
|
|
185
|
+
query: FilterQuery;
|
|
186
|
+
} | {
|
|
187
|
+
ok: false;
|
|
188
|
+
reason: string;
|
|
189
|
+
};
|
|
190
|
+
/** Every value a key is compared to with `=`, anywhere in the tree. */
|
|
191
|
+
declare function filterValuesFor(query: FilterQuery, key: string): string[];
|
|
192
|
+
/** Every comparison in the tree, in the order the filter writes them. */
|
|
193
|
+
declare function filterTerms(query: FilterQuery): FilterTerm[];
|
|
194
|
+
/** Every call in the tree, for a caller that reads one of them. */
|
|
195
|
+
declare function filterCalls(query: FilterQuery): FilterCall[];
|
|
196
|
+
/** Read one filter string, or say what stopped the reading. */
|
|
197
|
+
declare function parseFilterQuery(source: string): FilterParse;
|
|
198
|
+
|
|
84
199
|
/**
|
|
85
200
|
* The boundaries a Terraform configuration declares.
|
|
86
201
|
*
|
|
@@ -91,8 +206,10 @@ interface TerraformPack {
|
|
|
91
206
|
* A name is usually built at deploy time, and Terraform interpolates
|
|
92
207
|
* the same way CloudFormation does, so `"${local.environment}-orders"`
|
|
93
208
|
* becomes the pattern `{local.environment}-orders` and pairs with code
|
|
94
|
-
* that builds the same name from its own variable.
|
|
95
|
-
*
|
|
209
|
+
* that builds the same name from its own variable. An interpolation
|
|
210
|
+
* that refers to another resource in the same configuration resolves
|
|
211
|
+
* instead, since that resource states the value. The README says how a
|
|
212
|
+
* block that HCL states once or many times is read.
|
|
96
213
|
*/
|
|
97
214
|
|
|
98
215
|
interface TerraformReadOptions {
|
|
@@ -104,4 +221,4 @@ declare function terraformToSummaries(source: string, sourceFile: string, option
|
|
|
104
221
|
/** Read one `.tf` file, or every one directly inside a directory. */
|
|
105
222
|
declare function terraformFileToSummaries(target: string, options: TerraformReadOptions): BehavioralSummary[];
|
|
106
223
|
|
|
107
|
-
export { type MessageBusResource, type StorageResource, type TerraformPack, type TerraformReadOptions, type TerraformResource, type TerraformResourcePattern, terraformFileToSummaries, terraformToSummaries };
|
|
224
|
+
export { type AttributeMeaning, type FilterCall, type FilterParse, type FilterQuery, type FilterTerm, type MessageBusResource, type MetricReadingResource, type MetricResource, type StorageResource, type TerraformPack, type TerraformReadOptions, type TerraformResource, type TerraformResourcePattern, filterCalls, filterTerms, filterValuesFor, parseFilterQuery, terraformFileToSummaries, terraformToSummaries };
|