@usebruno/filestore 0.10.0 → 0.12.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/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/workers/worker-script.js +1 -1
- package/dist/cjs/workers/worker-script.js.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/workers/worker-script.js +1 -1
- package/dist/esm/workers/worker-script.js.map +1 -1
- package/dist/formats/bru/index.d.ts.map +1 -1
- package/dist/formats/bru/utils/redact-large-text-blocks.d.ts +11 -0
- package/dist/formats/bru/utils/redact-large-text-blocks.d.ts.map +1 -0
- package/dist/formats/yml/common/app.d.ts +8 -0
- package/dist/formats/yml/common/app.d.ts.map +1 -0
- package/dist/formats/yml/common/auth.d.ts.map +1 -1
- package/dist/formats/yml/common/body.d.ts.map +1 -1
- package/dist/formats/yml/common/datatype.d.ts +14 -0
- package/dist/formats/yml/common/datatype.d.ts.map +1 -0
- package/dist/formats/yml/common/headers.d.ts.map +1 -1
- package/dist/formats/yml/common/variables.d.ts +1 -2
- package/dist/formats/yml/common/variables.d.ts.map +1 -1
- package/dist/formats/yml/index.d.ts +3 -1
- package/dist/formats/yml/index.d.ts.map +1 -1
- package/dist/formats/yml/items/parseApp.d.ts +13 -0
- package/dist/formats/yml/items/parseApp.d.ts.map +1 -0
- package/dist/formats/yml/items/parseGraphQLRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/parseWebsocketRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyApp.d.ts +4 -0
- package/dist/formats/yml/items/stringifyApp.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -1
- package/dist/formats/yml/mockServerTypes.d.ts +95 -0
- package/dist/formats/yml/mockServerTypes.d.ts.map +1 -0
- package/dist/formats/yml/parseCollection.d.ts.map +1 -1
- package/dist/formats/yml/parseEnvironment.d.ts +3 -1
- package/dist/formats/yml/parseEnvironment.d.ts.map +1 -1
- package/dist/formats/yml/parseFolder.d.ts.map +1 -1
- package/dist/formats/yml/parseItem.d.ts.map +1 -1
- package/dist/formats/yml/parseMockServer.d.ts +4 -0
- package/dist/formats/yml/parseMockServer.d.ts.map +1 -0
- package/dist/formats/yml/stringifyCollection.d.ts.map +1 -1
- package/dist/formats/yml/stringifyEnvironment.d.ts +3 -1
- package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -1
- package/dist/formats/yml/stringifyFolder.d.ts.map +1 -1
- package/dist/formats/yml/stringifyItem.d.ts.map +1 -1
- package/dist/formats/yml/stringifyMockServer.d.ts +4 -0
- package/dist/formats/yml/stringifyMockServer.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/secretsJsonToEnvironments.d.ts +38 -0
- package/dist/utils/secretsJsonToEnvironments.d.ts.map +1 -0
- package/dist/workers/WorkerQueue/index.d.ts +3 -2
- package/dist/workers/WorkerQueue/index.d.ts.map +1 -1
- package/dist/workers/index.d.ts +4 -0
- package/dist/workers/index.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/constants.ts +13 -0
- package/src/formats/bru/index.ts +52 -0
- package/src/formats/bru/tests/parseBruEnvironment.spec.js +63 -0
- package/src/formats/bru/tests/redact-large-text-blocks.spec.js +472 -0
- package/src/formats/bru/utils/redact-large-text-blocks.ts +143 -0
- package/src/formats/yml/common/actions.ts +1 -1
- package/src/formats/yml/common/app.ts +27 -0
- package/src/formats/yml/common/auth.ts +53 -1
- package/src/formats/yml/common/body.spec.ts +62 -0
- package/src/formats/yml/common/body.ts +27 -9
- package/src/formats/yml/common/datatype.spec.ts +110 -0
- package/src/formats/yml/common/datatype.ts +57 -0
- package/src/formats/yml/common/headers.ts +4 -0
- package/src/formats/yml/common/variables.spec.ts +127 -0
- package/src/formats/yml/common/variables.ts +14 -22
- package/src/formats/yml/index.ts +5 -1
- package/src/formats/yml/items/parseApp.ts +37 -0
- package/src/formats/yml/items/parseGraphQLRequest.ts +14 -16
- package/src/formats/yml/items/parseGrpcRequest.ts +24 -3
- package/src/formats/yml/items/parseHttpRequest.ts +19 -16
- package/src/formats/yml/items/parseWebsocketRequest.ts +29 -9
- package/src/formats/yml/items/stringifyApp.ts +45 -0
- package/src/formats/yml/items/stringifyGraphQLRequest.ts +7 -6
- package/src/formats/yml/items/stringifyGrpcRequest.ts +9 -11
- package/src/formats/yml/items/stringifyHttpRequest.ts +14 -6
- package/src/formats/yml/items/stringifyWebsocketRequest.ts +22 -9
- package/src/formats/yml/mockServerTypes.ts +95 -0
- package/src/formats/yml/parseCollection.spec.ts +193 -0
- package/src/formats/yml/parseCollection.ts +24 -6
- package/src/formats/yml/parseEnvironment.spec.ts +99 -0
- package/src/formats/yml/parseEnvironment.ts +41 -19
- package/src/formats/yml/parseFolder.spec.ts +70 -0
- package/src/formats/yml/parseFolder.ts +19 -22
- package/src/formats/yml/parseItem.spec.ts +147 -0
- package/src/formats/yml/parseItem.ts +4 -0
- package/src/formats/yml/parseMockServer.spec.ts +180 -0
- package/src/formats/yml/parseMockServer.ts +113 -0
- package/src/formats/yml/stringifyCollection.spec.ts +223 -0
- package/src/formats/yml/stringifyCollection.ts +26 -9
- package/src/formats/yml/stringifyEnvironment.spec.ts +91 -0
- package/src/formats/yml/stringifyEnvironment.ts +55 -20
- package/src/formats/yml/stringifyFolder.spec.ts +70 -0
- package/src/formats/yml/stringifyFolder.ts +7 -2
- package/src/formats/yml/stringifyItem.spec.ts +53 -0
- package/src/formats/yml/stringifyItem.ts +4 -0
- package/src/formats/yml/stringifyMockServer.spec.ts +177 -0
- package/src/formats/yml/stringifyMockServer.ts +129 -0
- package/src/formats/yml/tests/defaultEnvironment.spec.js +50 -0
- package/src/formats/yml/tests/fixtures/presets/empty-request.yml +7 -0
- package/src/formats/yml/tests/fixtures/presets/no-presets.yml +3 -0
- package/src/formats/yml/tests/fixtures/presets/no-request-key.yml +6 -0
- package/src/formats/yml/tests/fixtures/presets/type-only-realistic.yml +24 -0
- package/src/formats/yml/tests/fixtures/presets/url-only-realistic.yml +25 -0
- package/src/formats/yml/tests/fixtures/presets/with-type-and-url.yml +9 -0
- package/src/formats/yml/tests/parseCollection.spec.js +63 -0
- package/src/formats/yml/tests/parseEnvironment.spec.js +24 -63
- package/src/formats/yml/tests/parseEnvironment.spec.ts +160 -0
- package/src/formats/yml/tests/stringifyEnvironment.spec.ts +230 -0
- package/src/formats/yml/tests/variables.spec.js +7 -7
- package/src/formats/yml/utils.ts +1 -1
- package/src/index.ts +39 -1
- package/src/types/bruno-lang.d.ts +1 -0
- package/src/types.ts +8 -0
- package/src/utils/secretsJsonToEnvironments.spec.ts +211 -0
- package/src/utils/secretsJsonToEnvironments.ts +129 -0
- package/src/workers/WorkerQueue/index.ts +10 -2
- package/src/workers/index.ts +25 -1
- package/src/workers/worker-script.ts +45 -21
- package/dist/formats/bru/tests/example-status-swap.spec.d.ts +0 -2
- package/dist/formats/bru/tests/example-status-swap.spec.d.ts.map +0 -1
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts +0 -57
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts.map +0 -1
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts +0 -2
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts.map +0 -1
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts +0 -2
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts.map +0 -1
- package/dist/formats/yml/tests/parseEnvironment.spec.d.ts +0 -2
- package/dist/formats/yml/tests/parseEnvironment.spec.d.ts.map +0 -1
- package/dist/formats/yml/tests/variables.spec.d.ts +0 -2
- package/dist/formats/yml/tests/variables.spec.d.ts.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import parseEnvironment from '../parseEnvironment';
|
|
2
|
+
|
|
3
|
+
describe('yml env parser', () => {
|
|
4
|
+
it('should parse empty variables', () => {
|
|
5
|
+
const input = `name: test\n`;
|
|
6
|
+
|
|
7
|
+
const output = parseEnvironment(input);
|
|
8
|
+
|
|
9
|
+
expect(output.name).toBe('test');
|
|
10
|
+
expect(output.variables).toEqual([]);
|
|
11
|
+
expect(output.externalSecrets).toBeUndefined();
|
|
12
|
+
expect(output.color).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should parse multiple regular variables with disabled flag', () => {
|
|
16
|
+
const input = `name: test
|
|
17
|
+
variables:
|
|
18
|
+
- name: url
|
|
19
|
+
value: http://localhost:3000
|
|
20
|
+
- name: port
|
|
21
|
+
value: "3000"
|
|
22
|
+
disabled: true
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const output = parseEnvironment(input);
|
|
26
|
+
|
|
27
|
+
expect(output.variables).toHaveLength(2);
|
|
28
|
+
expect(output.variables[0]).toMatchObject({ name: 'url', value: 'http://localhost:3000', enabled: true });
|
|
29
|
+
expect(output.variables[1]).toMatchObject({ name: 'port', value: '3000', enabled: false });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should parse a secret variable', () => {
|
|
33
|
+
const input = `name: test
|
|
34
|
+
variables:
|
|
35
|
+
- secret: true
|
|
36
|
+
name: token
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const output = parseEnvironment(input);
|
|
40
|
+
|
|
41
|
+
expect(output.variables).toHaveLength(1);
|
|
42
|
+
expect(output.variables[0]).toMatchObject({
|
|
43
|
+
name: 'token',
|
|
44
|
+
value: '',
|
|
45
|
+
enabled: true,
|
|
46
|
+
secret: true
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should parse a hashicorp-vault provider block with disabled entries', () => {
|
|
51
|
+
const input = `name: test
|
|
52
|
+
variables:
|
|
53
|
+
- name: url
|
|
54
|
+
value: http://localhost:3000
|
|
55
|
+
externalSecrets:
|
|
56
|
+
type: hashicorp-vault-cloud
|
|
57
|
+
variables:
|
|
58
|
+
- name: cloudSecret
|
|
59
|
+
path: secret/data/cloud
|
|
60
|
+
- name: dbPassword
|
|
61
|
+
path: secret/data/db-password
|
|
62
|
+
disabled: true
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const output = parseEnvironment(input);
|
|
66
|
+
|
|
67
|
+
expect(output.variables).toHaveLength(1);
|
|
68
|
+
expect(output.externalSecrets!.type).toBe('hashicorp-vault-cloud');
|
|
69
|
+
expect(output.externalSecrets!.variables).toMatchObject([
|
|
70
|
+
{ name: 'cloudSecret', path: 'secret/data/cloud', enabled: true },
|
|
71
|
+
{ name: 'dbPassword', path: 'secret/data/db-password', enabled: false }
|
|
72
|
+
]);
|
|
73
|
+
output.externalSecrets!.variables.forEach((variable: any) => {
|
|
74
|
+
expect(variable.uid).toMatch(/^[a-zA-Z0-9]{21}$/);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should parse an aws-secrets-manager provider block', () => {
|
|
79
|
+
const input = `name: test
|
|
80
|
+
externalSecrets:
|
|
81
|
+
type: aws-secrets-manager
|
|
82
|
+
variables:
|
|
83
|
+
- name: awsSecret
|
|
84
|
+
secretName: my-aws-secret
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
const output = parseEnvironment(input);
|
|
88
|
+
|
|
89
|
+
expect(output.externalSecrets!.type).toBe('aws-secrets-manager');
|
|
90
|
+
expect(output.externalSecrets!.variables).toMatchObject([{ name: 'awsSecret', secretName: 'my-aws-secret', enabled: true }]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should parse an azure-key-vault provider block', () => {
|
|
94
|
+
const input = `name: test
|
|
95
|
+
externalSecrets:
|
|
96
|
+
type: azure-key-vault
|
|
97
|
+
variables:
|
|
98
|
+
- name: azureSecret
|
|
99
|
+
vaultName: my-key-vault
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const output = parseEnvironment(input);
|
|
103
|
+
|
|
104
|
+
expect(output.externalSecrets!.type).toBe('azure-key-vault');
|
|
105
|
+
expect(output.externalSecrets!.variables).toMatchObject([{ name: 'azureSecret', vaultName: 'my-key-vault', enabled: true }]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should keep a half-filled row (a name with an empty identifier)', () => {
|
|
109
|
+
const input = `name: test
|
|
110
|
+
externalSecrets:
|
|
111
|
+
type: hashicorp-vault-server
|
|
112
|
+
variables:
|
|
113
|
+
- name: good
|
|
114
|
+
path: secret/data/good
|
|
115
|
+
- name: bad
|
|
116
|
+
path: ''
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
const output = parseEnvironment(input);
|
|
120
|
+
|
|
121
|
+
expect(output.externalSecrets!.type).toBe('hashicorp-vault-server');
|
|
122
|
+
expect(output.externalSecrets!.variables).toMatchObject([
|
|
123
|
+
{ name: 'good', path: 'secret/data/good', enabled: true },
|
|
124
|
+
{ name: 'bad', path: '', enabled: true }
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should parse a provider block with no variables', () => {
|
|
129
|
+
const input = `name: test
|
|
130
|
+
externalSecrets:
|
|
131
|
+
type: aws-secrets-manager
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
const output = parseEnvironment(input);
|
|
135
|
+
|
|
136
|
+
expect(output.externalSecrets!.type).toBe('aws-secrets-manager');
|
|
137
|
+
expect(output.externalSecrets!.variables).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should drop the block for an unknown provider type', () => {
|
|
141
|
+
const input = `name: test
|
|
142
|
+
externalSecrets:
|
|
143
|
+
type: made-up-provider
|
|
144
|
+
variables:
|
|
145
|
+
- name: x
|
|
146
|
+
path: p/x
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
const output = parseEnvironment(input);
|
|
150
|
+
expect(output.externalSecrets).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('should default name to Untitled Environment when missing', () => {
|
|
154
|
+
const input = `variables:\n - name: foo\n value: bar\n`;
|
|
155
|
+
|
|
156
|
+
const output = parseEnvironment(input);
|
|
157
|
+
|
|
158
|
+
expect(output.name).toBe('Untitled Environment');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import stringifyEnvironment from '../stringifyEnvironment';
|
|
2
|
+
|
|
3
|
+
describe('yml env stringifier', () => {
|
|
4
|
+
it('should stringify empty environment', () => {
|
|
5
|
+
const output = stringifyEnvironment({
|
|
6
|
+
uid: 'env1',
|
|
7
|
+
name: 'test',
|
|
8
|
+
variables: [],
|
|
9
|
+
color: null
|
|
10
|
+
} as any);
|
|
11
|
+
|
|
12
|
+
expect(output).toBe('name: test\n');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should stringify multiple regular variables with disabled flag', () => {
|
|
16
|
+
const output = stringifyEnvironment({
|
|
17
|
+
uid: 'env1',
|
|
18
|
+
name: 'test',
|
|
19
|
+
variables: [
|
|
20
|
+
{ uid: 'v1', name: 'url', value: 'http://localhost:3000', type: 'text', enabled: true },
|
|
21
|
+
{ uid: 'v2', name: 'port', value: '3000', type: 'text', enabled: false }
|
|
22
|
+
],
|
|
23
|
+
color: null
|
|
24
|
+
} as any);
|
|
25
|
+
|
|
26
|
+
expect(output).toBe(`name: test
|
|
27
|
+
variables:
|
|
28
|
+
- name: url
|
|
29
|
+
value: http://localhost:3000
|
|
30
|
+
- name: port
|
|
31
|
+
value: "3000"
|
|
32
|
+
disabled: true
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should stringify secret variables without their values', () => {
|
|
37
|
+
const output = stringifyEnvironment({
|
|
38
|
+
uid: 'env1',
|
|
39
|
+
name: 'test',
|
|
40
|
+
variables: [
|
|
41
|
+
{ uid: 'v1', name: 'token', value: 'secret-value-not-persisted', type: 'text', enabled: true, secret: true }
|
|
42
|
+
],
|
|
43
|
+
color: null
|
|
44
|
+
} as any);
|
|
45
|
+
|
|
46
|
+
expect(output).toBe(`name: test
|
|
47
|
+
variables:
|
|
48
|
+
- secret: true
|
|
49
|
+
name: token
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should stringify a hashicorp-vault provider block with disabled entries', () => {
|
|
54
|
+
const output = stringifyEnvironment({
|
|
55
|
+
uid: 'env1',
|
|
56
|
+
name: 'test',
|
|
57
|
+
variables: [
|
|
58
|
+
{ uid: 'v1', name: 'url', value: 'http://localhost:3000', type: 'text', enabled: true }
|
|
59
|
+
],
|
|
60
|
+
externalSecrets: {
|
|
61
|
+
type: 'hashicorp-vault-cloud',
|
|
62
|
+
variables: [
|
|
63
|
+
{ uid: 'e1', name: 'cloudSecret', path: 'secret/data/cloud', enabled: true },
|
|
64
|
+
{ uid: 'e2', name: 'dbPassword', path: 'secret/data/db-password', enabled: false }
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
color: null
|
|
68
|
+
} as any);
|
|
69
|
+
|
|
70
|
+
expect(output).toBe(`name: test
|
|
71
|
+
variables:
|
|
72
|
+
- name: url
|
|
73
|
+
value: http://localhost:3000
|
|
74
|
+
externalSecrets:
|
|
75
|
+
type: hashicorp-vault-cloud
|
|
76
|
+
variables:
|
|
77
|
+
- name: cloudSecret
|
|
78
|
+
path: secret/data/cloud
|
|
79
|
+
- name: dbPassword
|
|
80
|
+
path: secret/data/db-password
|
|
81
|
+
disabled: true
|
|
82
|
+
`);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should stringify an aws-secrets-manager provider block', () => {
|
|
86
|
+
const output = stringifyEnvironment({
|
|
87
|
+
uid: 'env1',
|
|
88
|
+
name: 'test',
|
|
89
|
+
variables: [],
|
|
90
|
+
externalSecrets: {
|
|
91
|
+
type: 'aws-secrets-manager',
|
|
92
|
+
variables: [
|
|
93
|
+
{ uid: 'e1', name: 'awsSecret', secretName: 'my-aws-secret', enabled: true }
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
color: null
|
|
97
|
+
} as any);
|
|
98
|
+
|
|
99
|
+
expect(output).toBe(`name: test
|
|
100
|
+
externalSecrets:
|
|
101
|
+
type: aws-secrets-manager
|
|
102
|
+
variables:
|
|
103
|
+
- name: awsSecret
|
|
104
|
+
secretName: my-aws-secret
|
|
105
|
+
`);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should stringify an azure-key-vault provider block', () => {
|
|
109
|
+
const output = stringifyEnvironment({
|
|
110
|
+
uid: 'env1',
|
|
111
|
+
name: 'test',
|
|
112
|
+
variables: [],
|
|
113
|
+
externalSecrets: {
|
|
114
|
+
type: 'azure-key-vault',
|
|
115
|
+
variables: [
|
|
116
|
+
{ uid: 'e1', name: 'azureSecret', vaultName: 'my-key-vault', enabled: true }
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
color: null
|
|
120
|
+
} as any);
|
|
121
|
+
|
|
122
|
+
expect(output).toBe(`name: test
|
|
123
|
+
externalSecrets:
|
|
124
|
+
type: azure-key-vault
|
|
125
|
+
variables:
|
|
126
|
+
- name: azureSecret
|
|
127
|
+
vaultName: my-key-vault
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should stringify a gcp-secrets-manager provider block, one row per project', () => {
|
|
132
|
+
const output = stringifyEnvironment({
|
|
133
|
+
uid: 'env1',
|
|
134
|
+
name: 'test',
|
|
135
|
+
variables: [],
|
|
136
|
+
externalSecrets: {
|
|
137
|
+
type: 'gcp-secrets-manager',
|
|
138
|
+
variables: [
|
|
139
|
+
{ uid: 'e1', name: 'staging', projectId: 'my-staging-project', enabled: true },
|
|
140
|
+
{ uid: 'e2', name: 'prod', projectId: 'my-prod-project', enabled: true }
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
color: null
|
|
144
|
+
} as any);
|
|
145
|
+
|
|
146
|
+
expect(output).toBe(`name: test
|
|
147
|
+
externalSecrets:
|
|
148
|
+
type: gcp-secrets-manager
|
|
149
|
+
variables:
|
|
150
|
+
- name: staging
|
|
151
|
+
projectId: my-staging-project
|
|
152
|
+
- name: prod
|
|
153
|
+
projectId: my-prod-project
|
|
154
|
+
`);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should keep a half-filled row (a name with an empty identifier)', () => {
|
|
158
|
+
const output = stringifyEnvironment({
|
|
159
|
+
uid: 'env1',
|
|
160
|
+
name: 'test',
|
|
161
|
+
variables: [],
|
|
162
|
+
externalSecrets: {
|
|
163
|
+
type: 'hashicorp-vault-server',
|
|
164
|
+
variables: [
|
|
165
|
+
{ uid: 'e1', name: 'good', path: 'secret/data/good', enabled: true },
|
|
166
|
+
{ uid: 'e2', name: 'bad', path: '', enabled: true }
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
color: null
|
|
170
|
+
} as any);
|
|
171
|
+
|
|
172
|
+
// The half-filled 'bad' row is serialized with an explicit empty identifier, not dropped.
|
|
173
|
+
expect(output).toContain(` - name: good
|
|
174
|
+
path: secret/data/good`);
|
|
175
|
+
expect(output).toContain(` - name: bad
|
|
176
|
+
path: ""`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('coerces a non-string identifier to a string (matching the parser) instead of dropping it', () => {
|
|
180
|
+
const output = stringifyEnvironment({
|
|
181
|
+
uid: 'env1',
|
|
182
|
+
name: 'test',
|
|
183
|
+
variables: [],
|
|
184
|
+
externalSecrets: {
|
|
185
|
+
type: 'hashicorp-vault-server',
|
|
186
|
+
variables: [{ uid: 'e1', name: 'num', path: 123, enabled: true }]
|
|
187
|
+
},
|
|
188
|
+
color: null
|
|
189
|
+
} as any);
|
|
190
|
+
|
|
191
|
+
// 123 is coerced to '123', not dropped to an empty identifier.
|
|
192
|
+
expect(output).toContain('123');
|
|
193
|
+
expect(output).not.toContain(`- name: num
|
|
194
|
+
path: ""`);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('should emit only the provider block when variables is empty', () => {
|
|
198
|
+
const output = stringifyEnvironment({
|
|
199
|
+
uid: 'env1',
|
|
200
|
+
name: 'test',
|
|
201
|
+
variables: [],
|
|
202
|
+
externalSecrets: {
|
|
203
|
+
type: 'aws-secrets-manager',
|
|
204
|
+
variables: []
|
|
205
|
+
},
|
|
206
|
+
color: null
|
|
207
|
+
} as any);
|
|
208
|
+
|
|
209
|
+
expect(output).toBe(`name: test
|
|
210
|
+
externalSecrets:
|
|
211
|
+
type: aws-secrets-manager
|
|
212
|
+
variables: []
|
|
213
|
+
`);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should not emit the external-secret section for an unknown provider type', () => {
|
|
217
|
+
const output = stringifyEnvironment({
|
|
218
|
+
uid: 'env1',
|
|
219
|
+
name: 'test',
|
|
220
|
+
variables: [],
|
|
221
|
+
externalSecrets: {
|
|
222
|
+
type: 'made-up-provider',
|
|
223
|
+
variables: [{ uid: 'e1', name: 'x', path: 'p/x', enabled: true }]
|
|
224
|
+
},
|
|
225
|
+
color: null
|
|
226
|
+
} as any);
|
|
227
|
+
|
|
228
|
+
expect(output).toBe('name: test\n');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toBrunoVariables, toOpenCollectionVariables } from '../common/variables';
|
|
2
2
|
|
|
3
3
|
describe('yml variables - typed values (collection / folder / request vars)', () => {
|
|
4
|
-
it('reads a typed value
|
|
4
|
+
it('reads a typed value coercing it to its native JS type and records the dataType', () => {
|
|
5
5
|
const ocVariables = [
|
|
6
6
|
{ name: 'var_str', value: 'plain' },
|
|
7
7
|
{ name: 'var_num', value: { type: 'number', data: '300' } },
|
|
@@ -12,16 +12,16 @@ describe('yml variables - typed values (collection / folder / request vars)', ()
|
|
|
12
12
|
const { req } = toBrunoVariables(ocVariables);
|
|
13
13
|
|
|
14
14
|
expect(req.find((v) => v.name === 'var_str')).toMatchObject({ value: 'plain' });
|
|
15
|
-
expect(req.find((v) => v.name === 'var_str')).not.toHaveProperty('
|
|
16
|
-
expect(req.find((v) => v.name === 'var_num')).toMatchObject({ value:
|
|
17
|
-
expect(req.find((v) => v.name === 'var_bool')).toMatchObject({ value:
|
|
18
|
-
expect(req.find((v) => v.name === 'var_obj')).toMatchObject({ value:
|
|
15
|
+
expect(req.find((v) => v.name === 'var_str')).not.toHaveProperty('dataType');
|
|
16
|
+
expect(req.find((v) => v.name === 'var_num')).toMatchObject({ value: 300, dataType: 'number' });
|
|
17
|
+
expect(req.find((v) => v.name === 'var_bool')).toMatchObject({ value: false, dataType: 'boolean' });
|
|
18
|
+
expect(req.find((v) => v.name === 'var_obj')).toMatchObject({ value: { scope: 'folder' }, dataType: 'object' });
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it('writes
|
|
21
|
+
it('writes dataType back as a { type, data } value, leaving plain strings untouched', () => {
|
|
22
22
|
const brunoVariables = [
|
|
23
23
|
{ uid: 'u1', name: 'var_str', value: 'plain', enabled: true, local: false },
|
|
24
|
-
{ uid: 'u2', name: 'var_num', value: '300',
|
|
24
|
+
{ uid: 'u2', name: 'var_num', value: '300', dataType: 'number', enabled: true, local: false }
|
|
25
25
|
];
|
|
26
26
|
|
|
27
27
|
const ocVariables = toOpenCollectionVariables(brunoVariables);
|
package/src/formats/yml/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as YAML from 'yaml';
|
|
2
2
|
|
|
3
3
|
// Top-level keys that should have a blank line before them
|
|
4
|
-
const BLOCK_KEYS = ['info', 'http', 'graphql', 'grpc', 'websocket', 'runtime', 'settings', 'examples', 'docs', 'items', 'request'];
|
|
4
|
+
const BLOCK_KEYS = ['info', 'http', 'graphql', 'grpc', 'websocket', 'mock', 'routes', 'runtime', 'settings', 'examples', 'docs', 'items', 'request'];
|
|
5
5
|
|
|
6
6
|
export const stringifyYml = (obj: any): string => {
|
|
7
7
|
const yamlStr = YAML.stringify(obj, {
|
package/src/index.ts
CHANGED
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
parseYmlCollection,
|
|
14
14
|
parseYmlFolder,
|
|
15
15
|
parseYmlEnvironment,
|
|
16
|
+
parseYmlMockServer,
|
|
16
17
|
stringifyYmlItem,
|
|
17
18
|
stringifyYmlFolder,
|
|
18
19
|
stringifyYmlCollection,
|
|
19
|
-
stringifyYmlEnvironment
|
|
20
|
+
stringifyYmlEnvironment,
|
|
21
|
+
stringifyYmlMockServer
|
|
20
22
|
} from './formats/yml';
|
|
21
23
|
import { dotenvToJson } from '@usebruno/lang';
|
|
22
24
|
import BruParserWorker from './workers';
|
|
@@ -27,6 +29,7 @@ import {
|
|
|
27
29
|
} from './types';
|
|
28
30
|
import { DEFAULT_COLLECTION_FORMAT } from './constants';
|
|
29
31
|
import { bruRequestParseAndRedactBodyData } from './formats/bru/utils/request-parse-and-redact-body-data';
|
|
32
|
+
import { redactLargeBruTextBlocks, restoreRedactedBlocks } from './formats/bru/utils/redact-large-text-blocks';
|
|
30
33
|
|
|
31
34
|
// request
|
|
32
35
|
export const parseRequest = (content: string, options: ParseOptions = { format: DEFAULT_COLLECTION_FORMAT }): any => {
|
|
@@ -74,6 +77,22 @@ export const stringifyRequestViaWorker = async (requestObj: any, options: { form
|
|
|
74
77
|
return await fileParserWorker.stringifyRequest(requestObj, options.format);
|
|
75
78
|
};
|
|
76
79
|
|
|
80
|
+
export const parseFolderViaWorker = async (content: string, options: { format: CollectionFormat }): Promise<any> => {
|
|
81
|
+
return await getWorkerInstance().parseFolder(content, options.format);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const stringifyFolderViaWorker = async (folderObj: any, options: { format: CollectionFormat }): Promise<string> => {
|
|
85
|
+
return await getWorkerInstance().stringifyFolder(folderObj, options.format);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const parseEnvironmentViaWorker = async (content: string, options: { format: CollectionFormat }): Promise<any> => {
|
|
89
|
+
return await getWorkerInstance().parseEnvironment(content, options.format);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const stringifyEnvironmentViaWorker = async (envObj: any, options: { format: CollectionFormat }): Promise<string> => {
|
|
93
|
+
return await getWorkerInstance().stringifyEnvironment(envObj, options.format);
|
|
94
|
+
};
|
|
95
|
+
|
|
77
96
|
// collection
|
|
78
97
|
export const parseCollection = (content: string, options: ParseOptions = { format: DEFAULT_COLLECTION_FORMAT }): any => {
|
|
79
98
|
if (options.format === 'bru') {
|
|
@@ -131,10 +150,29 @@ export const stringifyEnvironment = (envObj: BrunoEnvironment, options: Stringif
|
|
|
131
150
|
throw new Error(`Unsupported format: ${options.format}`);
|
|
132
151
|
};
|
|
133
152
|
|
|
153
|
+
// mock server — workspace-level entity, opencollection yml only
|
|
154
|
+
export const parseMockServer = (content: string, options: ParseOptions = { format: 'yml' }): any => {
|
|
155
|
+
if (options.format === 'yml') {
|
|
156
|
+
return parseYmlMockServer(content);
|
|
157
|
+
}
|
|
158
|
+
throw new Error(`Unsupported format: ${options.format}`);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const stringifyMockServer = (mockServerObj: any, options: StringifyOptions = { format: 'yml' }): string => {
|
|
162
|
+
if (options.format === 'yml') {
|
|
163
|
+
return stringifyYmlMockServer(mockServerObj);
|
|
164
|
+
}
|
|
165
|
+
throw new Error(`Unsupported format: ${options.format}`);
|
|
166
|
+
};
|
|
167
|
+
|
|
134
168
|
export const parseDotEnv = (content: string): Record<string, string> => {
|
|
135
169
|
return dotenvToJson(content);
|
|
136
170
|
};
|
|
137
171
|
|
|
172
|
+
export { redactLargeBruTextBlocks, restoreRedactedBlocks };
|
|
173
|
+
export type { RedactedBlock, RedactionResult } from './formats/bru/utils/redact-large-text-blocks';
|
|
174
|
+
export { migrateSecretsJsonToEnvironments } from './utils/secretsJsonToEnvironments';
|
|
175
|
+
|
|
138
176
|
export { BruParserWorker };
|
|
139
177
|
export * from './types';
|
|
140
178
|
export * from './constants';
|
|
@@ -6,4 +6,5 @@ declare module '@usebruno/lang' {
|
|
|
6
6
|
export function collectionBruToJson(bruContent: string): any;
|
|
7
7
|
export function jsonToCollectionBru(jsonData: any): string;
|
|
8
8
|
export function dotenvToJson(envContent: string): Record<string, string>;
|
|
9
|
+
export function outdentString(str: string, spaces?: number): string;
|
|
9
10
|
}
|