feat: add ksecret

This commit is contained in:
Bastien Riviere 2023-09-03 19:39:38 +02:00
parent f844352f9e
commit c3326d692b
Signed by: babariviere
GPG key ID: 4E5F0839249F162E
2 changed files with 29 additions and 1 deletions

View file

@ -33,7 +33,7 @@
packages.default = pkgs.buildGoApplication { packages.default = pkgs.buildGoApplication {
pname = "sealme"; pname = "sealme";
version = "0.1"; version = "0.2.0";
pwd = ./.; pwd = ./.;
src = ./.; src = ./.;
modules = ./gomod2nix.toml; modules = ./gomod2nix.toml;
@ -41,6 +41,30 @@
packages.sealme = config.packages.default; packages.sealme = config.packages.default;
packages.ksecret = let
build-inputs = with pkgs; [kubectl yq-go];
script = (pkgs.writeScriptBin "ksecret" (builtins.readFile ./scripts/ksecret.sh)).overrideAttrs (old: {
buildComamnd = "${old.buildCommand}\n patchShebangs $out";
});
completion-zsh =
pkgs.writeTextDir "share/zsh/site-functions/_ksecret"
''
compdef _ksecret ksecret
_ksecret() {
service=kubectl
CURRENT+=2
words="kubectl get secrets ''${words[@]:1}"
_kubectl
}
'';
in
pkgs.symlinkJoin {
name = "ksecret";
paths = [script completion-zsh];
buildInputs = [pkgs.makeWrapper];
postBuild = "wrapProgram $out/bin/ksecret --prefix PATH : ${pkgs.lib.makeBinPath build-inputs}";
};
treefmt = { treefmt = {
projectRootFile = ".git/config"; projectRootFile = ".git/config";
programs = { programs = {
@ -64,6 +88,7 @@
withSystem prev.stdenv.hostPlatform.system ( withSystem prev.stdenv.hostPlatform.system (
{config, ...}: { {config, ...}: {
sealme = config.packages.sealme; sealme = config.packages.sealme;
ksecret = config.packages.ksecret;
} }
); );
}; };

3
scripts/ksecret.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
kubectl get secrets $@ -o yaml | yq '.stringData = .data | del(.data) | .stringData.* |= @base64d'