this repo has no description

chore: cleanup, change dryrun to stdout

Alex Ottr 36fa2f58 2a241c6d

+28 -17
+12 -1
README.md
··· 36 36 37 37 ```yaml 38 38 interval: "10m" 39 - ageKeyPath: "keys/key.txt" 39 + age: 40 + identity: "keys/key.txt" 41 + recipients: # optional, when used to encrypt secrets 42 + - "age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 40 43 statePath: ".nox-state.json" 41 44 defaultRepo: git@github.com:ShorkBytes/nox-secrets.git 42 45 ··· 52 55 53 56 ```bash 54 57 nox --help 58 + ``` 59 + 60 + ### How to 61 + 62 + #### Decrypt secret into custom file 63 + 64 + ```bash 65 + nox decrypt --app debug --dry-run > secrets.env 55 66 ``` 56 67 57 68 ### Contributing
+10 -11
cmd/nox/main.go
··· 17 17 var configPath string 18 18 var statePath string 19 19 var identityPaths []string 20 - var appName string 20 + 21 21 var dryRun bool 22 22 var force bool 23 23 var verbose bool ··· 100 100 }, 101 101 }, 102 102 { 103 - Name: "export", 104 - Aliases: []string{"e"}, 105 - Usage: "Export all secrets to a single file", 103 + Name: "decrypt", 104 + Aliases: []string{"d"}, 105 + Usage: "Decrypts all secrets of one or all apps", 106 106 Flags: []cli.Flag{ 107 107 &cli.StringFlag{ 108 - Name: "app", 109 - Aliases: []string{"a"}, 110 - Usage: "app to export secrets for", 111 - Destination: &appName, 108 + Name: "app", 109 + Aliases: []string{"a"}, 110 + Usage: "app to decrypt secrets for", 112 111 }, 113 112 &cli.BoolFlag{ 114 113 Name: "dry-run", 115 114 Aliases: []string{"d"}, 116 115 Value: false, 117 - Usage: "only print what would be exported", 116 + Usage: "only print what would be decrypted", 118 117 Destination: &dryRun, 119 118 }, 120 119 &cli.BoolFlag{ ··· 132 131 IdentityPaths: identityPaths, 133 132 DryRun: dryRun, 134 133 Force: force, 135 - AppName: appName, 134 + AppName: cmd.String("app"), 136 135 Verbose: verbose, 137 136 }) 138 137 if err != nil { 139 138 log.Fatalf("failed to build runtime context: %v", err) 140 139 } 141 - if appName != "" { 140 + if cmd.String("app") != "" { 142 141 return processor.SyncApp(rtx) 143 142 } 144 143 return processor.SyncApps(rtx)
+1 -1
internal/gitrepo/utils.go
··· 7 7 func FileExistsInTree(tree *object.Tree, path string) bool { 8 8 _, err := tree.File(path) 9 9 return err == nil 10 - } 10 + }
+3 -2
internal/processor/gitsync.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "os" 5 6 6 7 "github.com/aottr/nox/internal/cache" 7 8 "github.com/aottr/nox/internal/config" ··· 45 46 cacheKey := state.GenerateKey(*appName, file.Path) 46 47 47 48 // skip if file is up to date and force is not set 48 - if !ctx.Force { 49 + if !ctx.Force && !ctx.DryRun { 49 50 if prevHash, ok := st.Data[cacheKey]; ok && prevHash == hash { 50 51 ctx.Logger.Printf("file %s is up to date", file.Path) 51 52 continue ··· 62 63 // skip writing file if dry run is set 63 64 if ctx.DryRun { 64 65 ctx.Logger.Printf("❌ dry run, not writing file %s", file.Output) 65 - fmt.Println(string(plaintext)) 66 + os.Stdout.Write(plaintext) 66 67 continue 67 68 } 68 69 WriteToFile(plaintext, file, &FileProcessorOptions{CreateDir: true})
+2 -2
internal/state/utils.go
··· 1 1 package state 2 2 3 3 import ( 4 - "fmt" 5 4 "crypto/sha256" 6 5 "encoding/hex" 6 + "fmt" 7 7 ) 8 8 9 9 // HashContent returns the SHA256 hash of the given data. ··· 14 14 15 15 func GenerateKey(appName, file string) string { 16 16 return fmt.Sprintf("%s:%s", appName, file) 17 - } 17 + }