Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package secrets
  2.  
  3. type PasswordStore interface {
  4. GetKey(key string) (string, error)
  5. }
  6.  
  7. func New(backend string, config map[string]interface{}) (PasswordStore, error) {
  8. switch backend {
  9. case "ansible":
  10. return ansible.New(config)
  11. default:
  12. return nil, fmt.Errorf("Password store '%s' not supported.", backend)
  13. }
  14. }
  15.  
  16.  
  17. package ansible
  18.  
  19.  
  20. type Connection interface {
  21. open() (string, error)
  22. }
  23.  
  24. type Ansible struct {
  25. connection Connection
  26. contents map[string]string
  27. }
  28.  
  29. func New(c map[string]interface{}) (*Ansible, error) {
  30. conn, err := NewConnection(c["ansible_path"].(string))
  31. if err != nil {
  32. return nil, err
  33. }
  34.  
  35. // open connection, parse, etc...
  36.  
  37. a := &Ansible{
  38. connection: conn,
  39. contents: parsedData,
  40. }
  41.  
  42. return a, nil
  43. }
  44.  
  45. package secrets
  46.  
  47. type PasswordStore interface {
  48. GetKey(key string) (string, error)
  49. }
  50.  
  51. func New(backend string, config map[string]interface{}) (PasswordStore, error) {
  52. switch backend {
  53. case "ansible":
  54. return ansible.New(AnsibleConnection{}, config)
  55. default:
  56. return nil, fmt.Errorf("Password store '%s' not supported.", backend)
  57. }
  58. }
  59.  
  60. package ansible
  61.  
  62.  
  63. // same as before in this file, but with injected dependency ...
  64.  
  65. func New(connect Connection, c map[string]interface{}) (*Ansible, error) {
  66. conn, err := connect.NewConnection(c["ansible_path"].(string))
  67. if err != nil {
  68. return nil, err
  69. }
  70.  
  71. // open connection, parse, etc...
  72.  
  73. a := &Ansible{
  74. connection: conn,
  75. contents: parsedData,
  76. }
  77.  
  78. return a, nil
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement