Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package secrets
- type PasswordStore interface {
- GetKey(key string) (string, error)
- }
- func New(backend string, config map[string]interface{}) (PasswordStore, error) {
- switch backend {
- case "ansible":
- return ansible.New(config)
- default:
- return nil, fmt.Errorf("Password store '%s' not supported.", backend)
- }
- }
- package ansible
- type Connection interface {
- open() (string, error)
- }
- type Ansible struct {
- connection Connection
- contents map[string]string
- }
- func New(c map[string]interface{}) (*Ansible, error) {
- conn, err := NewConnection(c["ansible_path"].(string))
- if err != nil {
- return nil, err
- }
- // open connection, parse, etc...
- a := &Ansible{
- connection: conn,
- contents: parsedData,
- }
- return a, nil
- }
- package secrets
- type PasswordStore interface {
- GetKey(key string) (string, error)
- }
- func New(backend string, config map[string]interface{}) (PasswordStore, error) {
- switch backend {
- case "ansible":
- return ansible.New(AnsibleConnection{}, config)
- default:
- return nil, fmt.Errorf("Password store '%s' not supported.", backend)
- }
- }
- package ansible
- // same as before in this file, but with injected dependency ...
- func New(connect Connection, c map[string]interface{}) (*Ansible, error) {
- conn, err := connect.NewConnection(c["ansible_path"].(string))
- if err != nil {
- return nil, err
- }
- // open connection, parse, etc...
- a := &Ansible{
- connection: conn,
- contents: parsedData,
- }
- return a, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement