credentialhelper

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 8 Imported by: 1

README

terraform-credential-helper-sdk

tests GoDoc

Framework for creating Terraform credentials helpers

Usage

func main () {
  cli := New("example", "dev", new(ExampleHelper))
  code, err = cli.Run(os.Args[1:])
  
  if err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
  }

  os.Exit(code)
}

type Helper struct{
  MyFlag string
}

func (h *Helper) Flags() *flag.FlagSet {
  flags := flag.NewFlagSet("example", flag.ContinueOnError)
  flags.StringVar(&h.MyFlag, "my-flag", "default", "usage")
  return flags
}

func (h *Helper) Get(hostname string) ([]byte, error) {
	return nil, nil
}

func (h *Helper) Store(hostname string, b []byte) error {
	return nil
}

func (h *Helper) Forget(hostname string) error {
	return nil
}

License

MIT © Ben Drucker

Documentation

Overview

Package credentialhelper helps create a Terraform credential helper CLI.

https://www.terraform.io/docs/internals/credentials-helpers.html

It accepts a "Helper" interface that implements the get, store, and forget command that Terraform will call. It prints output (or errors) to the correct output stream and sets an exit code based on the result of the Helper. It also supports defining flags, to be provided when the user defines their credential helper:

credentials_helper "credstore" {
  args = ["--host=credstore.example.com"]
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI is a Terraform credential helper CLI

func New

func New(name string, version string, helper Helper) *CLI

New creates a new credential helper CLI

func (*CLI) Run

func (c *CLI) Run(args []string) (int, error)

Run runs the CLI with the provided arguments

type Helper

type Helper interface {
	// Flags supported by the helper
	Flags() *flag.FlagSet

	// Retrieve the credentials for the given hostname
	Get(hostname string) (credentials []byte, err error)
	// Store new credentials for the given hostname
	Store(hostname string, credentials []byte) error
	// Delete any stored credentials for the given hostname
	Forget(hostname string) error
}

Helper represents a Terraform credential helper https://www.terraform.io/docs/internals/credentials-helpers.html

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL