Skip to content

Commit d13de30

Browse files
Merge pull request #776 from snyk/fix/outdates-deps
Fix/outdates deps
2 parents 1d1e01f + 5aa4556 commit d13de30

File tree

21 files changed

+1101
-929
lines changed

21 files changed

+1101
-929
lines changed

.eslintrc.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
},
77
"plugins": ["@typescript-eslint"],
88
"extends": [
9-
"plugin:@typescript-eslint/recommended",
10-
"prettier",
11-
"prettier/@typescript-eslint"
9+
"plugin:prettier/recommended",
10+
"prettier"
1211
],
1312
"rules": {
1413
"@typescript-eslint/semi": "error",
1514
"@typescript-eslint/no-use-before-define": "off",
1615
"@typescript-eslint/interface-name-prefix": "off",
1716
"@typescript-eslint/await-thenable": "error",
18-
"@typescript-eslint/ban-ts-ignore": "error",
17+
"@typescript-eslint/ban-ts-comment": "error",
1918
"@typescript-eslint/no-unnecessary-type-assertion": "error",
2019
"@typescript-eslint/unbound-method": "error"
2120
}

package-lock.json

Lines changed: 931 additions & 744 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@
3636
"@kubernetes/client-node": "^0.14.3",
3737
"@snyk/dep-graph": "^1.28.0",
3838
"async": "^3.2.0",
39-
"aws-sdk": "^2.873.0",
39+
"aws-sdk": "^2.916.0",
4040
"bunyan": "^1.8.15",
4141
"child-process-promise": "^2.2.1",
42-
"fs-extra": "^9.1.0",
43-
"lru-cache": "^5.1.1",
42+
"fs-extra": "^10.0.0",
43+
"lru-cache": "^6.0.0",
4444
"needle": "^2.6.0",
45-
"sleep-promise": "^8.0.1",
46-
"snyk-config": "4.0.0",
47-
"snyk-docker-plugin": "^4.20.3",
45+
"sleep-promise": "^9.1.0",
46+
"snyk-config": "5.0.0",
47+
"snyk-docker-plugin": "^4.20.9",
4848
"source-map-support": "^0.5.16",
4949
"tunnel": "0.0.6",
50-
"typescript": "^3.9.9",
50+
"typescript": "^4.3.2",
5151
"uuid": "^8.3.2",
5252
"yaml": "^1.10.2"
5353
},
@@ -57,21 +57,22 @@
5757
"@types/jest": "^26.0.21",
5858
"@types/lru-cache": "^5.1.0",
5959
"@types/needle": "^2.0.4",
60-
"@types/node": "^10.17.55",
61-
"@types/sinon": "^7.5.2",
62-
"@types/tunnel": "0.0.1",
60+
"@types/node": "^15.6.1",
61+
"@types/sinon": "^10.0.1",
62+
"@types/tunnel": "0.0.2",
6363
"@types/uuid": "^8.3.0",
64-
"@typescript-eslint/eslint-plugin": "^2.22.0",
65-
"@typescript-eslint/parser": "^2.22.0",
66-
"eslint": "^6.8.0",
67-
"eslint-config-prettier": "^6.10.0",
64+
"@typescript-eslint/eslint-plugin": "^4.25.0",
65+
"@typescript-eslint/parser": "^4.25.0",
66+
"eslint": "^7.27.0",
67+
"eslint-config-prettier": "^8.3.0",
68+
"eslint-plugin-prettier": "^3.4.0",
6869
"jest": "^26.6.3",
69-
"nock": "^11.9.1",
70-
"prettier": "^2.2.1",
71-
"sinon": "^8.1.1",
72-
"ts-jest": "^26.5.4",
73-
"ts-node": "^8.6.2",
74-
"tsc-watch": "^1.0.30"
70+
"nock": "^13.0.11",
71+
"prettier": "^2.3.0",
72+
"sinon": "^11.1.1",
73+
"ts-jest": "^26.5.6",
74+
"ts-node": "^10.0.0",
75+
"tsc-watch": "^4.4.0"
7576
},
7677
"release": {
7778
"branches": "staging",

src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const namespacesFilePath = '/etc/config/excludedNamespaces';
1010

1111
function loadExcludedNamespaces(): string[] | null {
1212
try {
13-
const data = readFileSync(namespacesFilePath, 'UTF-8');
13+
const data = readFileSync(namespacesFilePath, 'utf-8');
1414
const namespaces: string[] = data.split(/\r?\n/);
1515
return namespaces;
1616
} catch (err) {

src/scanner/images/docker-plugin-shim.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,24 @@ export interface Meta extends Partial<Record<string, string>> {
7777
export function extractFactsFromDockerPluginResponse(
7878
pluginResponse: PluginResponse,
7979
): ExtractedFacts {
80-
const depGraph: depGraphLib.DepGraph = pluginResponse.scanResults[0].facts.find(
81-
(fact) => fact.type === 'depGraph',
82-
)?.data;
80+
const depGraph: depGraphLib.DepGraph =
81+
pluginResponse.scanResults[0].facts.find(
82+
(fact) => fact.type === 'depGraph',
83+
)?.data;
8384

84-
const manifestFiles:
85-
| ManifestFile[]
86-
| undefined = pluginResponse.scanResults[0].facts.find(
87-
(fact) => fact.type === 'imageManifestFiles',
88-
)?.data;
85+
const manifestFiles: ManifestFile[] | undefined =
86+
pluginResponse.scanResults[0].facts.find(
87+
(fact) => fact.type === 'imageManifestFiles',
88+
)?.data;
8989

9090
const hashes: string[] | undefined = pluginResponse.scanResults[0].facts.find(
9191
(fact) => fact.type === 'keyBinariesHashes',
9292
)?.data;
9393

94-
const imageLayers:
95-
| string[]
96-
| undefined = pluginResponse.scanResults[0].facts.find(
97-
(fact) => fact.type === 'imageLayers',
98-
)?.data;
94+
const imageLayers: string[] | undefined =
95+
pluginResponse.scanResults[0].facts.find(
96+
(fact) => fact.type === 'imageLayers',
97+
)?.data;
9998

10099
const rootFs: string[] | undefined = pluginResponse.scanResults[0].facts.find(
101100
(fact) => fact.type === 'rootFs',
@@ -105,11 +104,10 @@ export function extractFactsFromDockerPluginResponse(
105104
(fact) => fact.type === 'imageId',
106105
)?.data;
107106

108-
const imageOsReleasePrettyName:
109-
| string
110-
| undefined = pluginResponse.scanResults[0].facts.find(
111-
(fact) => fact.type === 'imageOsReleasePrettyName',
112-
)?.data;
107+
const imageOsReleasePrettyName: string | undefined =
108+
pluginResponse.scanResults[0].facts.find(
109+
(fact) => fact.type === 'imageOsReleasePrettyName',
110+
)?.data;
113111

114112
const platform = pluginResponse.scanResults[0].identity.args?.platform;
115113

src/scanner/images/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ export async function removePulledImages(
8585
}
8686

8787
// Exported for testing
88-
export function getImageParts(
89-
imageWithTag: string,
90-
): { imageName: string; imageTag: string; imageDigest: string } {
88+
export function getImageParts(imageWithTag: string): {
89+
imageName: string;
90+
imageTag: string;
91+
imageDigest: string;
92+
} {
9193
// we're matching pattern: <registry:port_number>(optional)/<image_name>(mandatory):<image_tag>(optional)@<tag_identifier>(optional)
9294
// extracted from https://github.com/docker/distribution/blob/master/reference/regexp.go
93-
const regex = /^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?\/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:\/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\w][\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][A-Fa-f0-9]{32,}))?$/gi;
95+
const regex =
96+
/^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?\/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:\/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\w][\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][A-Fa-f0-9]{32,}))?$/gi;
9497
const groups = regex.exec(imageWithTag);
9598

9699
if (!groups) {
@@ -208,11 +211,10 @@ async function getDependencyTreeFromPluginResponse(
208211
pluginResponse: PluginResponse,
209212
imageName: string,
210213
): Promise<DependencyTree> {
211-
const osDepGraph:
212-
| DepGraph
213-
| undefined = pluginResponse.scanResults[0].facts.find(
214-
(fact) => fact.type === 'depGraph',
215-
)?.data;
214+
const osDepGraph: DepGraph | undefined =
215+
pluginResponse.scanResults[0].facts.find(
216+
(fact) => fact.type === 'depGraph',
217+
)?.data;
216218

217219
if (!osDepGraph) {
218220
throw new Error('Missing dependency graph');
@@ -222,9 +224,8 @@ async function getDependencyTreeFromPluginResponse(
222224
osDepGraph,
223225
osDepGraph.pkgManager.name,
224226
);
225-
const osScanResultFacts = extractFactsFromDockerPluginResponse(
226-
pluginResponse,
227-
);
227+
const osScanResultFacts =
228+
extractFactsFromDockerPluginResponse(pluginResponse);
228229
const dockerDepTree = buildDockerPropertiesOnDepTree(
229230
depTree,
230231
osScanResultFacts,

src/supervisor/watchers/handlers/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ async function isSupportedWorkload(
141141
const limit = 1; // Try to grab only a single object
142142
const resourceVersion = undefined; // List anything in the cluster
143143
const timeoutSeconds = 10; // Don't block the snyk-monitor indefinitely
144-
const attemptedApiCall = await kubernetesApiWrappers.retryKubernetesApiRequest(
145-
() =>
144+
const attemptedApiCall =
145+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
146146
k8sApi.customObjectsClient.listNamespacedCustomObject(
147147
'apps.openshift.io',
148148
'v1',
@@ -156,7 +156,7 @@ async function isSupportedWorkload(
156156
resourceVersion,
157157
timeoutSeconds,
158158
),
159-
);
159+
);
160160
return (
161161
attemptedApiCall !== undefined &&
162162
attemptedApiCall.response !== undefined &&

src/supervisor/watchers/handlers/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export const FALSY_WORKLOAD_NAME_MARKER = 'falsy workload name';
44

55
type WorkloadHandlerFunc = (workload: any) => Promise<void>;
66

7-
type ListWorkloadFunctionFactory = (
8-
namespace: string,
9-
) => () => Promise<{
7+
type ListWorkloadFunctionFactory = (namespace: string) => () => Promise<{
108
response: any;
119
body: any;
1210
}>;

src/supervisor/workload-reader.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const deploymentReader: IWorkloadReaderFunc = async (
1616
workloadName,
1717
namespace,
1818
) => {
19-
const deploymentResult = await kubernetesApiWrappers.retryKubernetesApiRequest(
20-
() => k8sApi.appsClient.readNamespacedDeployment(workloadName, namespace),
21-
);
19+
const deploymentResult =
20+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
21+
k8sApi.appsClient.readNamespacedDeployment(workloadName, namespace),
22+
);
2223
const deployment = deploymentResult.body;
2324

2425
if (
@@ -48,16 +49,16 @@ const deploymentConfigReader: IWorkloadReaderFunc = async (
4849
workloadName,
4950
namespace,
5051
) => {
51-
const deploymentResult = await kubernetesApiWrappers.retryKubernetesApiRequest(
52-
() =>
52+
const deploymentResult =
53+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
5354
k8sApi.customObjectsClient.getNamespacedCustomObject(
5455
'apps.openshift.io',
5556
'v1',
5657
namespace,
5758
'deploymentconfigs',
5859
workloadName,
5960
),
60-
);
61+
);
6162
const deployment: V1DeploymentConfig = deploymentResult.body;
6263

6364
if (
@@ -86,9 +87,10 @@ const replicaSetReader: IWorkloadReaderFunc = async (
8687
workloadName,
8788
namespace,
8889
) => {
89-
const replicaSetResult = await kubernetesApiWrappers.retryKubernetesApiRequest(
90-
() => k8sApi.appsClient.readNamespacedReplicaSet(workloadName, namespace),
91-
);
90+
const replicaSetResult =
91+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
92+
k8sApi.appsClient.readNamespacedReplicaSet(workloadName, namespace),
93+
);
9294
const replicaSet = replicaSetResult.body;
9395

9496
if (
@@ -118,9 +120,10 @@ const statefulSetReader: IWorkloadReaderFunc = async (
118120
workloadName,
119121
namespace,
120122
) => {
121-
const statefulSetResult = await kubernetesApiWrappers.retryKubernetesApiRequest(
122-
() => k8sApi.appsClient.readNamespacedStatefulSet(workloadName, namespace),
123-
);
123+
const statefulSetResult =
124+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
125+
k8sApi.appsClient.readNamespacedStatefulSet(workloadName, namespace),
126+
);
124127
const statefulSet = statefulSetResult.body;
125128

126129
if (
@@ -237,13 +240,13 @@ const replicationControllerReader: IWorkloadReaderFunc = async (
237240
workloadName,
238241
namespace,
239242
) => {
240-
const replicationControllerResult = await kubernetesApiWrappers.retryKubernetesApiRequest(
241-
() =>
243+
const replicationControllerResult =
244+
await kubernetesApiWrappers.retryKubernetesApiRequest(() =>
242245
k8sApi.coreClient.readNamespacedReplicationController(
243246
workloadName,
244247
namespace,
245248
),
246-
);
249+
);
247250
const replicationController = replicationControllerResult.body;
248251

249252
if (

src/transmitter/payload.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,38 @@ export function constructDepGraph(
1919
scannedImages: IScanResult[],
2020
workloadMetadata: IWorkload[],
2121
): IDependencyGraphPayload[] {
22-
const results = scannedImages.map(
23-
(scannedImage): IDependencyGraphPayload => {
24-
// We know that .find() won't return undefined
25-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
26-
const kubeWorkload: IWorkload = workloadMetadata.find(
27-
(meta) => meta.imageName === scannedImage.imageWithTag,
28-
)!;
22+
const results = scannedImages.map((scannedImage): IDependencyGraphPayload => {
23+
// We know that .find() won't return undefined
24+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25+
const kubeWorkload: IWorkload = workloadMetadata.find(
26+
(meta) => meta.imageName === scannedImage.imageWithTag,
27+
)!;
2928

30-
const { cluster, namespace, type, name } = kubeWorkload;
29+
const { cluster, namespace, type, name } = kubeWorkload;
3130

32-
const imageLocator: IImageLocator = {
33-
userLocator: config.INTEGRATION_ID,
34-
imageId: scannedImage.image,
35-
imageWithDigest: scannedImage.imageWithDigest,
36-
cluster,
37-
namespace,
38-
type,
39-
name,
40-
};
31+
const imageLocator: IImageLocator = {
32+
userLocator: config.INTEGRATION_ID,
33+
imageId: scannedImage.image,
34+
imageWithDigest: scannedImage.imageWithDigest,
35+
cluster,
36+
namespace,
37+
type,
38+
name,
39+
};
4140

42-
const monitorMetadata: IKubernetesMonitorMetadata = {
43-
agentId: config.AGENT_ID,
44-
namespace: config.NAMESPACE,
45-
version: config.MONITOR_VERSION,
46-
};
41+
const monitorMetadata: IKubernetesMonitorMetadata = {
42+
agentId: config.AGENT_ID,
43+
namespace: config.NAMESPACE,
44+
version: config.MONITOR_VERSION,
45+
};
4746

48-
return {
49-
imageLocator,
50-
agentId: config.AGENT_ID,
51-
dependencyGraph: JSON.stringify(scannedImage.pluginResult),
52-
metadata: monitorMetadata,
53-
};
54-
},
55-
);
47+
return {
48+
imageLocator,
49+
agentId: config.AGENT_ID,
50+
dependencyGraph: JSON.stringify(scannedImage.pluginResult),
51+
metadata: monitorMetadata,
52+
};
53+
});
5654

5755
return results;
5856
}

0 commit comments

Comments
 (0)