Refactor code and cleanup with stub completion
[aaf/sms.git] / sms-service / src / sms / backend / vault.go
1 /*
2  * Copyright 2018 Intel Corporation, Inc
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package backend
18
19 import (
20         vaultapi "github.com/hashicorp/vault/api"
21
22         smsconfig "sms/config"
23 )
24
25 // Vault is the main Struct used in Backend to initialize the struct
26 type Vault struct {
27         vaultClient *vaultapi.Client
28 }
29
30 // Init will initialize the vault connection
31 // TODO: Check to see if we need to wait for vault to be running
32 func (v *Vault) Init() error {
33         vaultCFG := vaultapi.DefaultConfig()
34         vaultCFG.Address = smsconfig.SMSConfig.VaultAddress
35
36         client, err := vaultapi.NewClient(vaultCFG)
37         if err != nil {
38                 return err
39         }
40
41         v.vaultClient = client
42         return nil
43 }
44
45 // GetStatus returns the current seal status of vault
46 func (v *Vault) GetStatus() (bool, error) {
47         sys := v.vaultClient.Sys()
48         sealStatus, err := sys.SealStatus()
49         if err != nil {
50                 return false, err
51         }
52
53         return sealStatus.Sealed, nil
54 }
55
56 // GetSecretDomain returns any information related to the secretDomain
57 // More information can be added in the future with updates to the struct
58 func (v *Vault) GetSecretDomain(name string) (SecretDomain, error) {
59
60         return SecretDomain{}, nil
61 }
62
63 // GetSecret returns a secret mounted on a particular domain name
64 // The secret itself is referenced via its name which translates to
65 // a mount path in vault
66 func (v *Vault) GetSecret(dom string, sec string) (Secret, error) {
67
68         return Secret{}, nil
69 }
70
71 // CreateSecretDomain mounts the kv backend on a path with the given name
72 func (v *Vault) CreateSecretDomain(name string) (SecretDomain, error) {
73
74         return SecretDomain{}, nil
75 }
76
77 // CreateSecret creates a secret mounted on a particular domain name
78 // The secret itself is mounted on a path specified by name
79 func (v *Vault) CreateSecret(dom string, sec Secret) (Secret, error) {
80
81         return Secret{}, nil
82 }
83
84 // DeleteSecretDomain deletes a secret domain which translates to
85 // an unmount operation on the given path in Vault
86 func (v *Vault) DeleteSecretDomain(name string) error {
87
88         return nil
89 }
90
91 // DeleteSecret deletes a secret mounted on the path provided
92 func (v *Vault) DeleteSecret(dom string, name string) error {
93
94         return nil
95 }