From c3326d692b973fdff66f3e54739b5330f40eac6b Mon Sep 17 00:00:00 2001 From: Bastien Riviere Date: Sun, 3 Sep 2023 19:39:38 +0200 Subject: [PATCH] feat: add ksecret --- flake.nix | 27 ++++++++++++++++++++++++++- scripts/ksecret.sh | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 scripts/ksecret.sh diff --git a/flake.nix b/flake.nix index 9d69ebc..68f9176 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ packages.default = pkgs.buildGoApplication { pname = "sealme"; - version = "0.1"; + version = "0.2.0"; pwd = ./.; src = ./.; modules = ./gomod2nix.toml; @@ -41,6 +41,30 @@ 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 = { projectRootFile = ".git/config"; programs = { @@ -64,6 +88,7 @@ withSystem prev.stdenv.hostPlatform.system ( {config, ...}: { sealme = config.packages.sealme; + ksecret = config.packages.ksecret; } ); }; diff --git a/scripts/ksecret.sh b/scripts/ksecret.sh new file mode 100755 index 0000000..4ab1eef --- /dev/null +++ b/scripts/ksecret.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +kubectl get secrets $@ -o yaml | yq '.stringData = .data | del(.data) | .stringData.* |= @base64d'