-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vault is supported for the following: As a well-known filesystem for TLS cert, TLS key and SSH signing key. For configuration secrets for cookie_secret, csrf_secret, oauth_client_id and oauth_client_secret options.
- Loading branch information
Showing
65 changed files
with
6,708 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package vault | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
// NewClient returns a new vault client. | ||
func NewClient(address, token string) (*Client, error) { | ||
config := &api.Config{ | ||
Address: address, | ||
} | ||
client, err := api.NewClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
client.SetToken(token) | ||
return &Client{ | ||
vault: client, | ||
}, nil | ||
} | ||
|
||
func parseName(name string) (path, key string) { | ||
name = strings.TrimPrefix(name, "/vault/") | ||
i := strings.LastIndex(name, "/") | ||
if i < 0 { | ||
return name, "" | ||
} | ||
return name[:i], name[i+1:] | ||
} | ||
|
||
// Client is a simple client for vault. | ||
type Client struct { | ||
vault *api.Client | ||
} | ||
|
||
// Read returns a secret for a given path and key of the form `/vault/secret/path/key`. | ||
// If the requested key cannot be read the original string is returned along with an error. | ||
func (c *Client) Read(value string) (string, error) { | ||
p, k := parseName(value) | ||
data, err := c.vault.Logical().Read(p) | ||
if err != nil { | ||
return value, err | ||
} | ||
if data == nil { | ||
return value, fmt.Errorf("no such key %s", k) | ||
} | ||
secret, ok := data.Data[k] | ||
if !ok { | ||
return value, fmt.Errorf("no such key %s", k) | ||
} | ||
return secret.(string), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package certutil | ||
package util | ||
|
||
import "golang.org/x/crypto/ssh" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package certutil | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
Oops, something went wrong.