mirror of
https://github.com/ImSingee/hammal.git
synced 2024-11-25 03:59:20 +08:00
disable org && support docker official images
This commit is contained in:
parent
413a3a4c6b
commit
11ceb5fc85
@ -3,11 +3,11 @@ import { Backend } from './backend'
|
|||||||
|
|
||||||
const PROXY_HEADER_ALLOW_LIST: string[] = ["accept", "user-agent", "accept-encoding"]
|
const PROXY_HEADER_ALLOW_LIST: string[] = ["accept", "user-agent", "accept-encoding"]
|
||||||
|
|
||||||
const ORG_NAME_BACKEND:{ [key: string]: string; } = {
|
// const ORG_NAME_BACKEND:{ [key: string]: string; } = {
|
||||||
"gcr": "https://gcr.io",
|
// "gcr": "https://gcr.io",
|
||||||
"k8sgcr": "https://k8s.gcr.io",
|
// "k8sgcr": "https://k8s.gcr.io",
|
||||||
"quay": "https://quay.io",
|
// "quay": "https://quay.io",
|
||||||
}
|
// }
|
||||||
|
|
||||||
const DEFAULT_BACKEND_HOST: string = "https://registry-1.docker.io"
|
const DEFAULT_BACKEND_HOST: string = "https://registry-1.docker.io"
|
||||||
|
|
||||||
@ -26,35 +26,44 @@ function copyProxyHeaders(inputHeaders: Headers) : Headers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function orgNameFromPath(pathname: string): string|null {
|
function orgNameFromPath(pathname: string): string|null {
|
||||||
const splitedPath: string[] = pathname.split("/", 3)
|
// const splitedPath: string[] = pathname.split("/", 3)
|
||||||
if (splitedPath.length === 3 && splitedPath[0] === "" && splitedPath[1] === "v2") {
|
// if (splitedPath.length === 3 && splitedPath[0] === "" && splitedPath[1] === "v2") {
|
||||||
return splitedPath[2].toLowerCase()
|
// return splitedPath[2].toLowerCase()
|
||||||
}
|
// }
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function hostByOrgName(orgName: string|null): string {
|
function hostByOrgName(orgName: string|null): string {
|
||||||
if (orgName !== null && orgName in ORG_NAME_BACKEND) {
|
// if (orgName !== null && orgName in ORG_NAME_BACKEND) {
|
||||||
return ORG_NAME_BACKEND[orgName]
|
// return ORG_NAME_BACKEND[orgName]
|
||||||
}
|
// }
|
||||||
return DEFAULT_BACKEND_HOST
|
return DEFAULT_BACKEND_HOST
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewritePathByOrg(orgName: string|null, pathname: string): string {
|
function rewritePath(orgName: string | null, pathname: string): string {
|
||||||
if (orgName === null || !(orgName in ORG_NAME_BACKEND)) {
|
let splitedPath = pathname.split("/");
|
||||||
return pathname
|
|
||||||
|
// /v2/repo -> /v2/library/repo
|
||||||
|
if (orgName === null && splitedPath.length === 3) {
|
||||||
|
splitedPath = [splitedPath[0], splitedPath[1], "library", splitedPath[2]]
|
||||||
}
|
}
|
||||||
const splitedPath: string[] = pathname.split("/")
|
|
||||||
const cleanSplitedPath = splitedPath.filter(function(value: string, index: number) {
|
return splitedPath.join("/")
|
||||||
return value !== orgName || index !== 2;
|
|
||||||
})
|
// if (orgName === null || !(orgName in ORG_NAME_BACKEND)) {
|
||||||
return cleanSplitedPath.join("/")
|
// return pathname
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const cleanSplitedPath = splitedPath.filter(function(value: string, index: number) {
|
||||||
|
// return value !== orgName || index !== 2;
|
||||||
|
// })
|
||||||
|
// return cleanSplitedPath.join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRegistryRequest(request: Request): Promise<Response> {
|
async function handleRegistryRequest(request: Request): Promise<Response> {
|
||||||
const reqURL = new URL(request.url)
|
const reqURL = new URL(request.url)
|
||||||
const orgName = orgNameFromPath(reqURL.pathname)
|
const orgName = orgNameFromPath(reqURL.pathname)
|
||||||
const pathname = rewritePathByOrg(orgName, reqURL.pathname)
|
const pathname = rewritePath(orgName, reqURL.pathname)
|
||||||
const host = hostByOrgName(orgName)
|
const host = hostByOrgName(orgName)
|
||||||
const tokenProvider = new TokenProvider()
|
const tokenProvider = new TokenProvider()
|
||||||
const backend = new Backend(host, tokenProvider)
|
const backend = new Backend(host, tokenProvider)
|
||||||
|
Loading…
Reference in New Issue
Block a user