-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Convert OCI registry acceptance tests to unit tests
- Loading branch information
1 parent
b2754c5
commit 4640825
Showing
8 changed files
with
215 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/cli/commands/test/iac/local-execution/rules/oci-registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as registryClient from '@snyk/docker-registry-v2-client'; | ||
|
||
export type GetManifestResponse = { | ||
schemaVersion: number; | ||
layers: Layer[]; | ||
}; | ||
|
||
export type Layer = { | ||
digest: string; | ||
}; | ||
|
||
export type GetLayerResponse = { | ||
blob: Buffer; | ||
}; | ||
|
||
export interface OciRegistry { | ||
getManifest(repository: string, tag: string): Promise<GetManifestResponse>; | ||
getLayer(repository: string, digest: string): Promise<GetLayerResponse>; | ||
} | ||
|
||
export class RemoteOciRegistry implements OciRegistry { | ||
private static options = { | ||
acceptManifest: 'application/vnd.oci.image.manifest.v1+json', | ||
acceptLayers: 'application/vnd.oci.image.layer.v1.tar+gzip', | ||
}; | ||
|
||
constructor( | ||
private registry: string, | ||
private username?: string, | ||
private password?: string, | ||
) {} | ||
|
||
getManifest(repository: string, tag: string): Promise<GetManifestResponse> { | ||
return registryClient.getManifest( | ||
this.registry, | ||
repository, | ||
tag, | ||
this.username, | ||
this.password, | ||
RemoteOciRegistry.options, | ||
); | ||
} | ||
|
||
async getLayer( | ||
repository: string, | ||
digest: string, | ||
): Promise<GetLayerResponse> { | ||
const blob = await registryClient.getLayer( | ||
this.registry, | ||
repository, | ||
digest, | ||
this.username, | ||
this.password, | ||
RemoteOciRegistry.options, | ||
); | ||
return { blob }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.