pepr 0.42.0 → 0.42.2

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.
Files changed (149) hide show
  1. package/dist/cli/build.d.ts +1 -0
  2. package/dist/cli/build.d.ts.map +1 -1
  3. package/dist/cli/build.helpers.d.ts +66 -0
  4. package/dist/cli/build.helpers.d.ts.map +1 -1
  5. package/dist/cli/deploy.d.ts +15 -0
  6. package/dist/cli/deploy.d.ts.map +1 -1
  7. package/dist/cli/dev.d.ts.map +1 -1
  8. package/dist/cli/format.d.ts.map +1 -1
  9. package/dist/cli/format.helpers.d.ts +3 -0
  10. package/dist/cli/format.helpers.d.ts.map +1 -0
  11. package/dist/cli/init/enums.d.ts +10 -0
  12. package/dist/cli/init/enums.d.ts.map +1 -0
  13. package/dist/cli/init/index.d.ts.map +1 -1
  14. package/dist/cli/init/templates.d.ts +15 -11
  15. package/dist/cli/init/templates.d.ts.map +1 -1
  16. package/dist/cli/init/utils.d.ts.map +1 -1
  17. package/dist/cli/init/walkthrough.d.ts +3 -2
  18. package/dist/cli/init/walkthrough.d.ts.map +1 -1
  19. package/dist/cli/kfc.d.ts.map +1 -1
  20. package/dist/cli/monitor.d.ts +23 -0
  21. package/dist/cli/monitor.d.ts.map +1 -1
  22. package/dist/cli/root.d.ts.map +1 -1
  23. package/dist/cli/update.d.ts.map +1 -1
  24. package/dist/cli/uuid.d.ts.map +1 -1
  25. package/dist/cli.js +483 -586
  26. package/dist/controller.js +1 -195
  27. package/dist/fixtures/loader.d.ts.map +1 -1
  28. package/dist/lib/assets/deploy.d.ts.map +1 -1
  29. package/dist/lib/assets/destroy.d.ts.map +1 -1
  30. package/dist/lib/assets/helm.d.ts +1 -1
  31. package/dist/lib/assets/helm.d.ts.map +1 -1
  32. package/dist/lib/assets/index.d.ts +1 -1
  33. package/dist/lib/assets/index.d.ts.map +1 -1
  34. package/dist/lib/assets/pods.d.ts +6 -22
  35. package/dist/lib/assets/pods.d.ts.map +1 -1
  36. package/dist/lib/assets/rbac.d.ts.map +1 -1
  37. package/dist/lib/assets/webhooks.d.ts.map +1 -1
  38. package/dist/lib/assets/yaml.d.ts.map +1 -1
  39. package/dist/lib/controller/index.d.ts +2 -2
  40. package/dist/lib/controller/index.d.ts.map +1 -1
  41. package/dist/lib/controller/store.d.ts +1 -2
  42. package/dist/lib/controller/store.d.ts.map +1 -1
  43. package/dist/lib/controller/storeCache.d.ts +2 -1
  44. package/dist/lib/controller/storeCache.d.ts.map +1 -1
  45. package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
  46. package/dist/lib/core/capability.d.ts.map +1 -0
  47. package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
  48. package/dist/lib/core/module.d.ts.map +1 -0
  49. package/dist/lib/core/queue.d.ts.map +1 -0
  50. package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
  51. package/dist/lib/core/schedule.d.ts.map +1 -0
  52. package/dist/lib/{storage.d.ts → core/storage.d.ts} +4 -4
  53. package/dist/lib/core/storage.d.ts.map +1 -0
  54. package/dist/lib/deploymentChecks.d.ts.map +1 -1
  55. package/dist/lib/errors.d.ts +0 -5
  56. package/dist/lib/errors.d.ts.map +1 -1
  57. package/dist/lib/filesystemService.d.ts.map +1 -1
  58. package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
  59. package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
  60. package/dist/lib/filter/filter.d.ts +33 -1
  61. package/dist/lib/filter/filter.d.ts.map +1 -1
  62. package/dist/lib/finalizer.d.ts.map +1 -1
  63. package/dist/lib/helpers.d.ts +4 -9
  64. package/dist/lib/helpers.d.ts.map +1 -1
  65. package/dist/lib/included-files.d.ts.map +1 -1
  66. package/dist/lib/mutate-request.d.ts +2 -2
  67. package/dist/lib/mutate-request.d.ts.map +1 -1
  68. package/dist/lib/processors/mutate-processor.d.ts +28 -0
  69. package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
  70. package/dist/lib/processors/validate-processor.d.ts +9 -0
  71. package/dist/lib/processors/validate-processor.d.ts.map +1 -0
  72. package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
  73. package/dist/lib/processors/watch-processor.d.ts.map +1 -0
  74. package/dist/lib/telemetry/logger.d.ts.map +1 -1
  75. package/dist/lib/telemetry/metrics.d.ts.map +1 -1
  76. package/dist/lib/utils.d.ts.map +1 -1
  77. package/dist/lib/validate-request.d.ts +2 -2
  78. package/dist/lib/validate-request.d.ts.map +1 -1
  79. package/dist/lib.d.ts +2 -2
  80. package/dist/lib.d.ts.map +1 -1
  81. package/dist/lib.js +508 -341
  82. package/dist/lib.js.map +4 -4
  83. package/dist/sdk/heredoc.d.ts.map +1 -1
  84. package/package.json +9 -9
  85. package/src/cli/build.helpers.ts +180 -0
  86. package/src/cli/build.ts +85 -133
  87. package/src/cli/deploy.ts +113 -74
  88. package/src/cli/dev.ts +2 -2
  89. package/src/cli/format.helpers.ts +27 -0
  90. package/src/cli/format.ts +4 -18
  91. package/src/cli/init/enums.ts +9 -0
  92. package/src/cli/init/index.ts +4 -3
  93. package/src/cli/init/templates.ts +30 -2
  94. package/src/cli/init/utils.ts +3 -3
  95. package/src/cli/init/walkthrough.ts +7 -8
  96. package/src/cli/kfc.ts +1 -1
  97. package/src/cli/monitor.ts +108 -65
  98. package/src/cli/root.ts +1 -1
  99. package/src/cli/update.ts +1 -1
  100. package/src/cli/uuid.ts +1 -1
  101. package/src/fixtures/loader.ts +2 -2
  102. package/src/lib/assets/deploy.ts +11 -11
  103. package/src/lib/assets/destroy.ts +1 -1
  104. package/src/lib/assets/helm.ts +6 -6
  105. package/src/lib/assets/index.ts +23 -23
  106. package/src/lib/assets/pods.ts +11 -6
  107. package/src/lib/assets/webhooks.ts +31 -46
  108. package/src/lib/assets/yaml.ts +12 -9
  109. package/src/lib/controller/index.ts +13 -11
  110. package/src/lib/controller/store.ts +25 -12
  111. package/src/lib/controller/storeCache.ts +16 -3
  112. package/src/lib/{capability.ts → core/capability.ts} +25 -14
  113. package/src/lib/{module.ts → core/module.ts} +10 -10
  114. package/src/lib/{queue.ts → core/queue.ts} +13 -5
  115. package/src/lib/{storage.ts → core/storage.ts} +33 -24
  116. package/src/lib/deploymentChecks.ts +2 -2
  117. package/src/lib/errors.ts +3 -8
  118. package/src/lib/filesystemService.ts +1 -1
  119. package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
  120. package/src/lib/filter/filter.ts +204 -111
  121. package/src/lib/finalizer.ts +2 -2
  122. package/src/lib/helpers.ts +20 -133
  123. package/src/lib/included-files.ts +1 -1
  124. package/src/lib/mutate-request.ts +11 -11
  125. package/src/lib/processors/mutate-processor.ts +225 -0
  126. package/src/lib/processors/validate-processor.ts +93 -0
  127. package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +19 -15
  128. package/src/lib/telemetry/logger.ts +3 -1
  129. package/src/lib/tls.ts +5 -1
  130. package/src/lib/utils.ts +5 -5
  131. package/src/lib/validate-request.ts +4 -4
  132. package/src/lib.ts +2 -2
  133. package/src/runtime/controller.ts +2 -2
  134. package/src/sdk/cosign.ts +4 -4
  135. package/src/sdk/heredoc.ts +1 -1
  136. package/dist/lib/capability.d.ts.map +0 -1
  137. package/dist/lib/module.d.ts.map +0 -1
  138. package/dist/lib/mutate-processor.d.ts +0 -6
  139. package/dist/lib/mutate-processor.d.ts.map +0 -1
  140. package/dist/lib/queue.d.ts.map +0 -1
  141. package/dist/lib/schedule.d.ts.map +0 -1
  142. package/dist/lib/storage.d.ts.map +0 -1
  143. package/dist/lib/validate-processor.d.ts +0 -6
  144. package/dist/lib/validate-processor.d.ts.map +0 -1
  145. package/dist/lib/watch-processor.d.ts.map +0 -1
  146. package/src/lib/mutate-processor.ts +0 -165
  147. package/src/lib/validate-processor.ts +0 -85
  148. /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
  149. /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/lib/queue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAIxE,KAAK,aAAa,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAUjF;;GAEG;AACH,qBAAa,KAAK,CAAC,CAAC,SAAS,gBAAgB;;gBAM/B,IAAI,EAAE,MAAM;IAKxB,KAAK;;;;IAIL,KAAK;;;;;;;;;IASL;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa;CAsE7D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../src/lib/schedule.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAElF,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CAC7B;AAED,qBAAa,UAAW,YAAW,QAAQ;IACzC,UAAU,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAQ;IACz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IAAI,CAAC,CAgB9C;IAEF,SAAS,eAAgB,YAAY,KAAG,CAAC,MAAM,IAAI,CAAC,CAIlD;IAEF,OAAO,aAAc,YAAY,KAAG,IAAI,CAEtC;IAEF;;;OAGG;IACH,WAAW,QAAS,MAAM,KAAG,IAAI,CAE/B;CAqBH"}
@@ -1,6 +0,0 @@
1
- import { Capability } from "./capability";
2
- import { ValidateResponse } from "./k8s";
3
- import { AdmissionRequest } from "./types";
4
- import { ModuleConfig } from "./module";
5
- export declare function validateProcessor(config: ModuleConfig, capabilities: Capability[], req: AdmissionRequest, reqMetadata: Record<string, string>): Promise<ValidateResponse[]>;
6
- //# sourceMappingURL=validate-processor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate-processor.d.ts","sourceRoot":"","sources":["../../src/lib/validate-processor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,GAAG,EAAE,gBAAgB,EACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAiE7B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch-processor.d.ts","sourceRoot":"","sources":["../../src/lib/watch-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,gBAAgB,EAAY,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEvF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAQhC;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,gBAAgB,UAkB7C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,2BAMrD;AAuBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,UAAU,EAAE,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,QAMlF;AA+GD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,GAAE,MAAW,EAAE,GAAG,CAAC,EAAE,gBAAgB,QAOvF"}
@@ -1,165 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
-
4
- import jsonPatch from "fast-json-patch";
5
- import { kind } from "kubernetes-fluent-client";
6
-
7
- import { Capability } from "./capability";
8
- import { Errors } from "./errors";
9
- import { shouldSkipRequest } from "./filter/filter";
10
- import { MutateResponse } from "./k8s";
11
- import { AdmissionRequest } from "./types";
12
- import Log from "./telemetry/logger";
13
- import { ModuleConfig } from "./module";
14
- import { PeprMutateRequest } from "./mutate-request";
15
- import { base64Encode, convertFromBase64Map, convertToBase64Map } from "./utils";
16
-
17
- export async function mutateProcessor(
18
- config: ModuleConfig,
19
- capabilities: Capability[],
20
- req: AdmissionRequest,
21
- reqMetadata: Record<string, string>,
22
- ): Promise<MutateResponse> {
23
- const wrapped = new PeprMutateRequest(req);
24
- const response: MutateResponse = {
25
- uid: req.uid,
26
- warnings: [],
27
- allowed: false,
28
- };
29
-
30
- // Track whether any capability matched the request
31
- let matchedAction = false;
32
-
33
- // Track data fields that should be skipped during decoding
34
- let skipDecode: string[] = [];
35
-
36
- // If the resource is a secret, decode the data
37
- const isSecret = req.kind.version === "v1" && req.kind.kind === "Secret";
38
- if (isSecret) {
39
- skipDecode = convertFromBase64Map(wrapped.Raw as unknown as kind.Secret);
40
- }
41
-
42
- Log.info(reqMetadata, `Processing request`);
43
-
44
- for (const { name, bindings, namespaces } of capabilities) {
45
- const actionMetadata = { ...reqMetadata, name };
46
- for (const action of bindings) {
47
- // Skip this action if it's not a mutate action
48
- if (!action.mutateCallback) {
49
- continue;
50
- }
51
-
52
- // Continue to the next action without doing anything if this one should be skipped
53
- const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
54
- if (shouldSkip !== "") {
55
- Log.debug(shouldSkip);
56
- continue;
57
- }
58
-
59
- const label = action.mutateCallback.name;
60
- Log.info(actionMetadata, `Processing mutation action (${label})`);
61
- matchedAction = true;
62
-
63
- // Add annotations to the request to indicate that the capability started processing
64
- // this will allow tracking of failed mutations that were permitted to continue
65
- const updateStatus = (status: string) => {
66
- // Only update the status if the request is a CREATE or UPDATE (we don't use CONNECT)
67
- if (req.operation === "DELETE") {
68
- return;
69
- }
70
-
71
- const identifier = `${config.uuid}.pepr.dev/${name}`;
72
- wrapped.Raw.metadata = wrapped.Raw.metadata || {};
73
- wrapped.Raw.metadata.annotations = wrapped.Raw.metadata.annotations || {};
74
- wrapped.Raw.metadata.annotations[identifier] = status;
75
- };
76
-
77
- updateStatus("started");
78
-
79
- try {
80
- // Run the action
81
- await action.mutateCallback(wrapped);
82
-
83
- // Log on success
84
- Log.info(actionMetadata, `Mutation action succeeded (${label})`);
85
-
86
- // Add annotations to the request to indicate that the capability succeeded
87
- updateStatus("succeeded");
88
- } catch (e) {
89
- updateStatus("warning");
90
- response.warnings = response.warnings || [];
91
-
92
- const errorMessage = logMutateErrorMessage(e);
93
-
94
- // Log on failure
95
- Log.error(actionMetadata, `Action failed: ${errorMessage}`);
96
- response.warnings.push(`Action failed: ${errorMessage}`);
97
-
98
- switch (config.onError) {
99
- case Errors.reject:
100
- Log.error(actionMetadata, `Action failed: ${errorMessage}`);
101
- response.result = "Pepr module configured to reject on error";
102
- return response;
103
-
104
- case Errors.audit:
105
- response.auditAnnotations = response.auditAnnotations || {};
106
- response.auditAnnotations[Date.now()] = `Action failed: ${errorMessage}`;
107
- break;
108
- }
109
- }
110
- }
111
- }
112
-
113
- // If we've made it this far, the request is allowed
114
- response.allowed = true;
115
-
116
- // If no capability matched the request, exit early
117
- if (!matchedAction) {
118
- Log.info(reqMetadata, `No matching actions found`);
119
- return response;
120
- }
121
-
122
- // delete operations can't be mutate, just return before the transformation
123
- if (req.operation === "DELETE") {
124
- return response;
125
- }
126
-
127
- const transformed = wrapped.Raw;
128
-
129
- // Post-process the Secret requests to convert it back to the original format
130
- if (isSecret) {
131
- convertToBase64Map(transformed as unknown as kind.Secret, skipDecode);
132
- }
133
-
134
- // Compare the original request to the modified request to get the patches
135
- const patches = jsonPatch.compare(req.object, transformed);
136
-
137
- // Only add the patch if there are patches to apply
138
- if (patches.length > 0) {
139
- response.patchType = "JSONPatch";
140
- // Webhook must be base64-encoded
141
- // https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#response
142
- response.patch = base64Encode(JSON.stringify(patches));
143
- }
144
-
145
- // Remove the warnings array if it's empty
146
- if (response.warnings && response.warnings.length < 1) {
147
- delete response.warnings;
148
- }
149
-
150
- Log.debug({ ...reqMetadata, patches }, `Patches generated`);
151
-
152
- return response;
153
- }
154
-
155
- const logMutateErrorMessage = (e: Error): string => {
156
- try {
157
- if (e.message && e.message !== "[object Object]") {
158
- return e.message;
159
- } else {
160
- throw new Error("An error occurred in the mutate action.");
161
- }
162
- } catch (e) {
163
- return "An error occurred with the mutate action.";
164
- }
165
- };
@@ -1,85 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
-
4
- import { kind } from "kubernetes-fluent-client";
5
-
6
- import { Capability } from "./capability";
7
- import { shouldSkipRequest } from "./filter/filter";
8
- import { ValidateResponse } from "./k8s";
9
- import { AdmissionRequest } from "./types";
10
- import Log from "./telemetry/logger";
11
- import { convertFromBase64Map } from "./utils";
12
- import { PeprValidateRequest } from "./validate-request";
13
- import { ModuleConfig } from "./module";
14
-
15
- export async function validateProcessor(
16
- config: ModuleConfig,
17
- capabilities: Capability[],
18
- req: AdmissionRequest,
19
- reqMetadata: Record<string, string>,
20
- ): Promise<ValidateResponse[]> {
21
- const wrapped = new PeprValidateRequest(req);
22
- const response: ValidateResponse[] = [];
23
-
24
- // If the resource is a secret, decode the data
25
- const isSecret = req.kind.version === "v1" && req.kind.kind === "Secret";
26
- if (isSecret) {
27
- convertFromBase64Map(wrapped.Raw as unknown as kind.Secret);
28
- }
29
-
30
- Log.info(reqMetadata, `Processing validation request`);
31
-
32
- for (const { name, bindings, namespaces } of capabilities) {
33
- const actionMetadata = { ...reqMetadata, name };
34
-
35
- for (const action of bindings) {
36
- // Skip this action if it's not a validation action
37
- if (!action.validateCallback) {
38
- continue;
39
- }
40
-
41
- const localResponse: ValidateResponse = {
42
- uid: req.uid,
43
- allowed: true, // Assume it's allowed until a validation check fails
44
- };
45
-
46
- // Continue to the next action without doing anything if this one should be skipped
47
- const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
48
- if (shouldSkip !== "") {
49
- Log.debug(shouldSkip);
50
- continue;
51
- }
52
-
53
- const label = action.validateCallback.name;
54
- Log.info(actionMetadata, `Processing validation action (${label})`);
55
-
56
- try {
57
- // Run the validation callback, if it fails set allowed to false
58
- const resp = await action.validateCallback(wrapped);
59
- localResponse.allowed = resp.allowed;
60
-
61
- // If the validation callback returned a status code or message, set it in the Response
62
- if (resp.statusCode || resp.statusMessage) {
63
- localResponse.status = {
64
- code: resp.statusCode || 400,
65
- message: resp.statusMessage || `Validation failed for ${name}`,
66
- };
67
- }
68
-
69
- Log.info(actionMetadata, `Validation action complete (${label}): ${resp.allowed ? "allowed" : "denied"}`);
70
- } catch (e) {
71
- // If any validation throws an error, note the failure in the Response
72
- Log.error(actionMetadata, `Action failed: ${JSON.stringify(e)}`);
73
- localResponse.allowed = false;
74
- localResponse.status = {
75
- code: 500,
76
- message: `Action failed with error: ${JSON.stringify(e)}`,
77
- };
78
- return [localResponse];
79
- }
80
- response.push(localResponse);
81
- }
82
- }
83
-
84
- return response;
85
- }
File without changes
File without changes