Replace oras with native OCI registry client and add login
- Talk to OCI Distribution v2 registries directly over HTTP/TLS; oras is no longer required on PATH - Add `orbit login <host>` and `orbit logout <host>`; credentials go to $ORBIT_ROOT/auth.json (mode 0600) - Fall back to Docker config (credHelpers and credsStore) when no Orbit credentials exist - Verify layer downloads with streaming SHA-256 - Fall back to the next channel only on HTTP 404 instead of matching oras error text - Update README and moon.mod to drop oras references
This commit is contained in:
1 parent
f8c9b99ee3
commit
0919ce105c
13 files changed
+2652
-184
No files matched your search
+57
-11
@@ -1,11 +1,14 @@
|
||||
// orbit: a package manager whose repository is any OCI registry, via ORAS.
|
||||
// orbit: a package manager whose repository is any OCI registry.
|
||||
|
||||
///|
|
||||
let usage : String =
|
||||
#|orbit - packages as OCI artifacts (via oras)
|
||||
#|orbit - packages as OCI artifacts
|
||||
#|
|
||||
#|usage:
|
||||
#| orbit init create folders and config.toml
|
||||
#| orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]
|
||||
#| log in to an OCI registry
|
||||
#| orbit logout <host> remove stored registry credentials
|
||||
#| orbit channel list channels, highest priority first
|
||||
#| orbit channel add <name> <url> [--plain-http]
|
||||
#| orbit publish <dir> [--channel <name>] [--no-latest]
|
||||
@@ -24,9 +27,9 @@ let usage : String =
|
||||
#|
|
||||
#|constraints: 1.2.3 =1.2.3 1.2 ^1.2.0 ~1.2.0 >=1.2 *
|
||||
#|config: <orbit root>/config.toml
|
||||
#|credentials: <orbit root>/auth.json (falls back to ~/.docker/config.json)
|
||||
#|environment: ORBIT_ROOT (default ~/.orbit); ORBIT_REGISTRY and
|
||||
#| ORBIT_PLAIN_HTTP=1 override the built-in main channel
|
||||
#|authentication: run `oras login <registry-host>` once.
|
||||
|
||||
///|
|
||||
/// Create the directories, and a config.toml if there is no config yet.
|
||||
@@ -69,18 +72,47 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
let pos : Array[String] = []
|
||||
let flags : Array[String] = []
|
||||
let mut publish_to = MAIN_CHANNEL
|
||||
let mut username : String? = None
|
||||
let mut password : String? = None
|
||||
let mut i = 1
|
||||
while i < args.length() {
|
||||
if args[i] == "--channel" {
|
||||
let a = args[i]
|
||||
if a == "--channel" {
|
||||
if cmd != "publish" || i + 1 >= args.length() {
|
||||
raise OrbitError("usage: orbit publish <dir> --channel <name>")
|
||||
}
|
||||
publish_to = args[i + 1]
|
||||
i = i + 1
|
||||
} else if has_prefix(args[i], "--") {
|
||||
flags.push(args[i])
|
||||
} else if a == "-u" || a == "--username" {
|
||||
if cmd != "login" || i + 1 >= args.length() {
|
||||
raise OrbitError(
|
||||
"usage: orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]",
|
||||
)
|
||||
}
|
||||
username = Some(args[i + 1])
|
||||
i = i + 1
|
||||
} else if has_prefix(a, "--username=") {
|
||||
if cmd != "login" {
|
||||
raise OrbitError("unknown flag '\{a}'")
|
||||
}
|
||||
username = Some(drop_chars(a, 11))
|
||||
} else if a == "-p" || a == "--password" {
|
||||
if cmd != "login" || i + 1 >= args.length() {
|
||||
raise OrbitError(
|
||||
"usage: orbit login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]",
|
||||
)
|
||||
}
|
||||
password = Some(args[i + 1])
|
||||
i = i + 1
|
||||
} else if has_prefix(a, "--password=") {
|
||||
if cmd != "login" {
|
||||
raise OrbitError("unknown flag '\{a}'")
|
||||
}
|
||||
password = Some(drop_chars(a, 11))
|
||||
} else if has_prefix(a, "--") {
|
||||
flags.push(a)
|
||||
} else {
|
||||
pos.push(args[i])
|
||||
pos.push(a)
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
@@ -94,6 +126,24 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
}
|
||||
cmd_init()
|
||||
}
|
||||
"login" => {
|
||||
need(
|
||||
pos,
|
||||
1,
|
||||
"login <host> [-u <user>] [-p <pass> | --password-stdin] [--plain-http]",
|
||||
)
|
||||
cmd_login(
|
||||
pos[0],
|
||||
username,
|
||||
password,
|
||||
flags.contains("--password-stdin"),
|
||||
flags.contains("--plain-http"),
|
||||
)
|
||||
}
|
||||
"logout" => {
|
||||
need(pos, 1, "logout <host>")
|
||||
cmd_logout(pos[0])
|
||||
}
|
||||
"channel" => {
|
||||
need(pos, 1, "channel list|add")
|
||||
match pos[0] {
|
||||
@@ -141,10 +191,6 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
||||
|
||||
///|
|
||||
async fn main {
|
||||
if sh("command -v oras >/dev/null 2>&1") != 0 {
|
||||
println("orbit: error: `oras` not found on PATH (https://oras.land)")
|
||||
c_exit(1)
|
||||
}
|
||||
dispatch(cli_args()) catch {
|
||||
OrbitError(msg) => {
|
||||
println("orbit: error: \{msg}")
|
||||
|
||||
Reference in new issue
Block a user