mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-02-23 08:28:03 +00:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
68
dot_config/nushell/nu_scripts/modules/docker/registry.nu
Normal file
68
dot_config/nushell/nu_scripts/modules/docker/registry.nu
Normal file
@@ -0,0 +1,68 @@
|
||||
def "nu-complete registry show" [cmd: string, offset: int] {
|
||||
let new = $cmd | str ends-with ' '
|
||||
let cmd = $cmd | split row ' '
|
||||
let url = $cmd.3?
|
||||
let reg = $cmd.4?
|
||||
let tag = $cmd.5?
|
||||
let auth = if ($env.REGISTRY_TOKEN? | is-not-empty) {
|
||||
[-H $"Authorization: Basic ($env.REGISTRY_TOKEN)"]
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
if ($tag | is-empty) and (not $new) or ($reg | is-empty) {
|
||||
curl -sSL ...$auth $"($url)/v2/_catalog"
|
||||
| from json | get repositories
|
||||
} else {
|
||||
curl -sSL ...$auth $"($url)/v2/($reg)/tags/list"
|
||||
| from json | get tags
|
||||
}
|
||||
}
|
||||
|
||||
### docker registry show
|
||||
export def "docker registry show" [
|
||||
url: string
|
||||
reg?: string@"nu-complete registry show"
|
||||
tag?: string@"nu-complete registry show"
|
||||
] {
|
||||
let header = if ($env.REGISTRY_TOKEN? | is-not-empty) {
|
||||
[-H $"Authorization: Basic ($env.REGISTRY_TOKEN)"]
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
| append [-H 'Accept: application/vnd.oci.image.manifest.v1+json']
|
||||
if ($reg | is-empty) {
|
||||
curl -sSL ...$header $"($url)/v2/_catalog" | from json | get repositories
|
||||
} else if ($tag | is-empty) {
|
||||
curl -sSL ...$header $"($url)/v2/($reg)/tags/list" | from json | get tags
|
||||
} else {
|
||||
curl -sSL ...$header $"($url)/v2/($reg)/manifests/($tag)" | from json
|
||||
}
|
||||
}
|
||||
|
||||
### docker registry delete
|
||||
export def "docker registry delete" [
|
||||
url: string
|
||||
reg: string@"nu-complete registry show"
|
||||
tag: string@"nu-complete registry show"
|
||||
] {
|
||||
let header = if ($env.REGISTRY_TOKEN? | is-not-empty) {
|
||||
[-H $"Authorization: Basic ($env.REGISTRY_TOKEN)"]
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
| append [-H 'Accept: application/vnd.oci.image.manifest.v1+json']
|
||||
#| append [-H 'Accept: application/vnd.docker.distribution.manifest.v2+json']
|
||||
let digest = do -i {
|
||||
curl -sSI ...$header $"($url)/v2/($reg)/manifests/($tag)"
|
||||
| rg docker-content-digest
|
||||
| split row ' '
|
||||
| get 1
|
||||
| str trim
|
||||
}
|
||||
print -e $digest
|
||||
if ($digest | is-not-empty) {
|
||||
curl -sSL -X DELETE ...$header $"($url)/v2/($reg)/manifests/($digest)"
|
||||
} else {
|
||||
'not found'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user