This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from jaxxstorm/refactor_vaultclient
Move the vault client into its own function
- Loading branch information
Showing
2 changed files
with
26 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package vault | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/go-cleanhttp" | ||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
func VaultClient(hostName string, hostPort int) (*api.Client, error) { | ||
|
||
// init a clean httpClient | ||
httpClient := cleanhttp.DefaultPooledClient() | ||
|
||
// format the URL with the passed host and por | ||
url := fmt.Sprintf("https://%s:%v", hostName, hostPort) | ||
|
||
// create a vault client | ||
client, err := api.NewClient(&api.Config{Address: url, HttpClient: httpClient}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return client, nil | ||
|
||
} |