Created
          December 2, 2015 15:43 
        
      - 
      
- 
        Save mlafeldt/487e0b8466ba48e15cc2 to your computer and use it in GitHub Desktop. 
    Talk to Vault using GitHub auth backend
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | package main | |
| import ( | |
| "log" | |
| "os" | |
| "github.com/hashicorp/vault/api" | |
| "github.com/hashicorp/vault/builtin/credential/github" | |
| ) | |
| func main() { | |
| config := api.DefaultConfig() | |
| config.Address = os.Getenv("VAULT_ADDR") | |
| client, err := api.NewClient(config) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| handler := &github.CLIHandler{} | |
| vars := map[string]string{ | |
| "token": os.Getenv("GITHUB_VAULT_TOKEN"), | |
| } | |
| token, err := handler.Auth(client, vars) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| client.SetToken(token) | |
| path := "secret/some-path" | |
| data := map[string]interface{}{ | |
| "hello": "world", | |
| "foo": "bar", | |
| } | |
| secret, err := client.Logical().Write(path, data) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| if secret == nil { | |
| log.Printf("Success! Data written to: %s", path) | |
| } | |
| secret, err = client.Logical().Read(path) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| if secret == nil { | |
| log.Fatalf("No value found at %s", path) | |
| } | |
| log.Printf("Secret data: %v\n", secret.Data) | |
| if _, err = client.Logical().Delete(path); err != nil { | |
| log.Fatalf("Error deleting '%s': %s", path, err) | |
| } | |
| log.Printf("Success! Deleted '%s'", path) | |
| } | 
      
      
  Author
  
  
        
      
            mlafeldt
  
      
      
      commented 
        Dec 2, 2015 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment