@@ -13,7 +13,9 @@ export const DEVCONTAINER_COLLECTION_LAYER_MEDIATYPE = 'application/vnd.devconta
1313
1414export type HEADERS = { 'authorization' ?: string ; 'user-agent' : string ; 'content-type' ?: string ; 'accept' ?: string } ;
1515
16- // ghcr.io/devcontainers/features/go:1.0.0
16+ // Represents the unique OCI identifier for a Feature or Template.
17+ // eg: ghcr.io/devcontainers/features/go:1.0.0
18+ // Constructed by 'getRef()'
1719export interface OCIRef {
1820 registry : string ; // 'ghcr.io'
1921 owner : string ; // 'devcontainers'
@@ -24,11 +26,14 @@ export interface OCIRef {
2426 version ?: string ; // '1.0.0'
2527}
2628
27- // ghcr.io/devcontainers/features:latest
29+ // Represents the unique OCI identifier for a Collection's Metadata artifact.
30+ // eg: ghcr.io/devcontainers/features:latest
31+ // Constructed by 'getCollectionRef()'
2832export interface OCICollectionRef {
2933 registry : string ; // 'ghcr.io'
3034 path : string ; // 'devcontainers/features'
31- version : 'latest' ; // 'latest'
35+ resource : string ; // 'ghcr.io/devcontainers/features'
36+ version : 'latest' ; // 'latest' (always)
3237}
3338
3439export interface OCILayer {
@@ -100,13 +105,15 @@ export function getRef(output: Log, input: string): OCIRef | undefined {
100105
101106 const path = `${ namespace } /${ id } ` ;
102107
103- output . write ( `resource: ${ resource } ` , LogLevel . Trace ) ;
104- output . write ( `id: ${ id } ` , LogLevel . Trace ) ;
105- output . write ( `version: ${ version } ` , LogLevel . Trace ) ;
106- output . write ( `owner: ${ owner } ` , LogLevel . Trace ) ;
107- output . write ( `namespace: ${ namespace } ` , LogLevel . Trace ) ; // TODO: We assume 'namespace' includes at least one slash (eg: 'devcontainers/features')
108- output . write ( `registry: ${ registry } ` , LogLevel . Trace ) ;
109- output . write ( `path: ${ path } ` , LogLevel . Trace ) ;
108+ output . write ( `> input: ${ input } ` , LogLevel . Trace ) ;
109+ output . write ( `>` , LogLevel . Trace ) ;
110+ output . write ( `> resource: ${ resource } ` , LogLevel . Trace ) ;
111+ output . write ( `> id: ${ id } ` , LogLevel . Trace ) ;
112+ output . write ( `> version: ${ version } ` , LogLevel . Trace ) ;
113+ output . write ( `> owner: ${ owner } ` , LogLevel . Trace ) ;
114+ output . write ( `> namespace: ${ namespace } ` , LogLevel . Trace ) ; // TODO: We assume 'namespace' includes at least one slash (eg: 'devcontainers/features')
115+ output . write ( `> registry: ${ registry } ` , LogLevel . Trace ) ;
116+ output . write ( `> path: ${ path } ` , LogLevel . Trace ) ;
110117
111118 // Validate results of parse.
112119
@@ -131,6 +138,31 @@ export function getRef(output: Log, input: string): OCIRef | undefined {
131138 } ;
132139}
133140
141+ export function getCollectionRef ( output : Log , registry : string , namespace : string ) : OCICollectionRef | undefined {
142+ // Normalize input by downcasing entire string
143+ registry = registry . toLowerCase ( ) ;
144+ namespace = namespace . toLowerCase ( ) ;
145+
146+ const path = namespace ;
147+ const resource = `${ registry } /${ path } ` ;
148+
149+ output . write ( `> Inputs: registry='${ registry } ' namespace='${ namespace } '` , LogLevel . Trace ) ;
150+ output . write ( `>` , LogLevel . Trace ) ;
151+ output . write ( `> resource: ${ resource } ` , LogLevel . Trace ) ;
152+
153+ if ( ! regexForPath . exec ( path ) ) {
154+ output . write ( `Parsed path '${ path } ' from input failed validation.` , LogLevel . Error ) ;
155+ return undefined ;
156+ }
157+
158+ return {
159+ registry,
160+ path,
161+ resource,
162+ version : 'latest'
163+ } ;
164+ }
165+
134166// Validate if a manifest exists and is reachable about the declared feature/template.
135167// Specification: https://github.com/opencontainers/distribution-spec/blob/v1.0.1/spec.md#pulling-manifests
136168export async function fetchOCIManifestIfExists ( output : Log , env : NodeJS . ProcessEnv , ref : OCIRef | OCICollectionRef , manifestDigest ?: string , authToken ?: string ) : Promise < OCIManifest | undefined > {
0 commit comments