Adding token creation for operations
[aaf/sms.git] / sms-service / src / sms / config / config.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 config
18
19 import (
20         "encoding/json"
21         "os"
22 )
23
24 // SMSConfiguration loads up all the values that are used to configure
25 // backend implementations
26 // TODO: Review these and see if they can be created/discovered dynamically
27 type SMSConfiguration struct {
28         CAFile     string `json:"cafile"`
29         ServerCert string `json:"servercert"`
30         ServerKey  string `json:"serverkey"`
31
32         VaultAddress string `json:"vaultaddress"`
33         VaultToken   string `json:"vaulttoken"`
34 }
35
36 // SMSConfig is the structure that stores the configuration
37 var SMSConfig *SMSConfiguration
38
39 // ReadConfigFile reads the specified smsConfig file to setup some env variables
40 func ReadConfigFile(file string) (*SMSConfiguration, error) {
41         if SMSConfig == nil {
42                 f, err := os.Open(file)
43                 if err != nil {
44                         return nil, err
45                 }
46
47                 decoder := json.NewDecoder(f)
48                 err = decoder.Decode(&SMSConfig)
49                 if err != nil {
50                         return nil, err
51                 }
52         }
53
54         return SMSConfig, nil
55 }