2 * Copyright 2018 Intel Corporation, Inc
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 vaultapi "github.com/hashicorp/vault/api"
22 smsconfig "sms/config"
25 // Vault is the main Struct used in Backend to initialize the struct
27 vaultClient *vaultapi.Client
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
36 client, err := vaultapi.NewClient(vaultCFG)
41 v.vaultClient = client
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()
53 return sealStatus.Sealed, nil
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) {
60 return SecretDomain{}, nil
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) {
71 // CreateSecretDomain mounts the kv backend on a path with the given name
72 func (v *Vault) CreateSecretDomain(name string) (SecretDomain, error) {
74 return SecretDomain{}, nil
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) {
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 {
91 // DeleteSecret deletes a secret mounted on the path provided
92 func (v *Vault) DeleteSecret(dom string, name string) error {