Skip to content

Commit

Permalink
packages name change
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaardsholt committed Sep 8, 2020
1 parent e1052c5 commit 7d919cf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
var input util.SecretJSON

if secretFile != "" { // --file is being used
data = files.ReadFile(secretFile)
data = files.Read(secretFile)
input = util.ReadInput(data)
} else if secret != "" { // Parameters is being used
if config.Config.Output == "" {
Expand All @@ -49,11 +49,11 @@ var (
fileName := fmt.Sprintf("secrets.%s", config.Config.Format)

if config.Config.Format == "json" {
files.WriteFile(config.Config.Output, fileName, allSecrets.ToJSON())
files.Write(config.Config.Output, fileName, allSecrets.ToJSON())
}

if config.Config.Format == "env" {
files.WriteFile(config.Config.Output, fileName, allSecrets.ToENV())
files.Write(config.Config.Output, fileName, allSecrets.ToENV())
}
color.Green.Printf("Secrets written to file: %s/%s\n", config.Config.Output, fileName)
},
Expand Down
Empty file modified docker-entrypoint.sh
100644 → 100755
Empty file.
16 changes: 14 additions & 2 deletions files/writeFile.go → files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ package files

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
)

// WriteFile will write some string data to a file
func WriteFile(output string, fileName string, content string) {
// Read will read the the content of a file and return it as a string.
func Read(filePath string) string {
data, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Printf("Unable to read the file at path '%s': %v\n", filePath, err)
os.Exit(1)
}

return fmt.Sprint(string(data))
}

// Write will write some string data to a file
func Write(output string, fileName string, content string) {
fileName = fixFileName(fileName)
path := filepath.Join(output, fileName)

Expand Down
32 changes: 0 additions & 32 deletions files/readFile.go

This file was deleted.

18 changes: 18 additions & 0 deletions token/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package token

import (
"github.com/BESTSELLER/harpocrates/config"
"github.com/BESTSELLER/harpocrates/files"
)

// Read will read a file and return the content as string
func Read() string {
// Defaults to Kubernetes Service Account
filePath := "/var/run/secrets/kubernetes.io/serviceaccount/token"

if config.Config.TokenPath != "" {
filePath = config.Config.TokenPath
}

return files.Read(filePath)
}
2 changes: 1 addition & 1 deletion util/extractSecrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ExtractSecrets(input SecretJSON) secrets.Result {
var secretValue = vault.ReadSecretKey(fmt.Sprintf("%s", c), h)
if *i.SaveAsFile {
fmt.Println("Creating file...", h)
files.WriteFile(input.Output, fmt.Sprintf("%s%s", currentPrefix, h), secretValue)
files.Write(input.Output, fmt.Sprintf("%s%s", currentPrefix, h), secretValue)
} else {
result.Add(h, secretValue, currentPrefix)
}
Expand Down
4 changes: 2 additions & 2 deletions vault/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"

"github.com/BESTSELLER/harpocrates/config"
"github.com/BESTSELLER/harpocrates/files"
"github.com/BESTSELLER/harpocrates/token"
)

// VaultLoginResult contains the result after logging in.
Expand Down Expand Up @@ -56,7 +56,7 @@ func Login() {
url := config.Config.VaultAddress + "/v1/auth/" + config.Config.ClusterName + "/login"

b := new(bytes.Buffer)
err := json.NewEncoder(b).Encode(JWTPayLoad{Jwt: files.ReadTokenFile(), Role: config.Config.ClusterName})
err := json.NewEncoder(b).Encode(JWTPayLoad{Jwt: token.Read(), Role: config.Config.ClusterName})
if err != nil {
fmt.Printf("Unable to prepare jwt token: %v\n", err)
os.Exit(1)
Expand Down

0 comments on commit 7d919cf

Please sign in to comment.