Adding logging framework
[aaf/sms.git] / sms-service / src / sms / backend / backend.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         smsconfig "sms/config"
21         smslogger "sms/log"
22 )
23
24 // SecretDomain is where Secrets are stored.
25 // A single domain can have any number of secrets
26 type SecretDomain struct {
27         UUID string `json:"uuid"`
28         Name string `json:"name"`
29 }
30
31 // SecretKeyValue is building block for a Secret
32 type SecretKeyValue struct {
33         Key   string `json:"name"`
34         Value string `json:"value"`
35 }
36
37 // Secret is the struct that defines the structure of a secret
38 // A single Secret can have any number of SecretKeyValue pairs
39 type Secret struct {
40         Name   string                 `json:"name"`
41         Values map[string]interface{} `json:"values"`
42 }
43
44 // SecretBackend interface that will be implemented for various secret backends
45 type SecretBackend interface {
46         Init() error
47
48         GetStatus() (bool, error)
49         GetSecretDomain(name string) (SecretDomain, error)
50         GetSecret(dom string, sec string) (Secret, error)
51
52         ListSecret(dom string) ([]string, error)
53
54         CreateSecretDomain(name string) (SecretDomain, error)
55         CreateSecret(dom string, sec Secret) error
56
57         DeleteSecretDomain(name string) error
58         DeleteSecret(dom string, name string) error
59 }
60
61 // InitSecretBackend returns an interface implementation
62 func InitSecretBackend() (SecretBackend, error) {
63         backendImpl := &Vault{
64                 vaultAddress: smsconfig.SMSConfig.VaultAddress,
65                 vaultToken:   smsconfig.SMSConfig.VaultToken,
66         }
67
68         err := backendImpl.Init()
69         if err != nil {
70                 smslogger.WriteError(err.Error())
71                 return nil, err
72         }
73
74         return backendImpl, nil
75 }
76
77 // LoginBackend Interface that will be implemented for various login backends
78 type LoginBackend interface {
79 }