mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00

- new function `kube refine` - define the required information in `$env.KUBERNETES_REFINE`, `kube refine` will collect information according to its definition - definitions in `status` and `cluster_status` are runtime information and will not be collected. They are used in the `kg` command to display status - normalize the output of the `kg`, `kgp`, `kgs` command using `krefine` - rename `kcconf` to `kccc` (kubectl change context clone) - a new module, `refine.nu`, declaratively extracts data from complex structures. - `container-list` additionally displays the cmd field of the image --------- Co-authored-by: nash <nash@iffy.me>
68 lines
2.1 KiB
Text
68 lines
2.1 KiB
Text
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'
|
|
}
|
|
}
|