Skip to content

tecnologer/go-secrets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Secrets

This tool can help you to manage the secrets key for a Golang project, keeping in secrets all sensitive data. I.e.: username and password for a database server.

How to use it

go get -u github.com/tecnologer/go-secrets

To initialize the bucket, use go-secrets-cli init. go-secrets-cli is here. If you don't want use CLI, you can get the bucket with secrets.GetBucketByUUID(<uuid.UUID>) or secrets.GetBucketByID(<string uuid>)

Code:

package main

import (
    "fmt"

	"github.com/tecnologer/go-secrets"
)

func main() {
	secrets.Init()

    username := secrets.Get("username")

	fmt.Printf("Secret username: %s", username)
}

For security use go-secrets-cli to add new keys:

go-secrets-cli set -key username -val tecnologer

  • Create a group of keys and use it
package main

import (
    "fmt"

	"github.com/tecnologer/go-secrets"
)

func main() {
	secrets.InitWithConfig(&config.Config{EncryptionEnabled: false})

	// For security use CLI to add new keys
	// Create a group for SQL authentication
    secrets.Set("SQL.Username", "tecno")
	secrets.Set("SQL.pwd", "123")
	secrets.Set("SQL.host", "localhost")
	secrets.Set("SQL.database", "test")

	sql, err := testdeep.GetGroup("SQL")
	if err == nil {
		fmt.Println("SQL keys:")
		fmt.Printf("Server=%v;Database=%v;User Id=%v;Password=%v;\n", sql.Get("host"), sql.Get("database"), sql.Get("Username"), sql.Get("pwd"))
	}

	fmt.Println("All keys:")
	bucket, err := secrets.Get()
	if err != nil {
		panic(err)
	}

	for key, val := range bucket.Secrets {
		fmt.Printf("%s: %v\n", key, val)
	}

	key := "SQL.pwd"
	fmt.Printf("Get key in other package. {%s: %v}\n", key, testdeep.GetKey(key))

	fmt.Println(bucket.ID)
}

Dependencies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages