AOSharedServiceLibrary
app_profile.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #include <string>
26 #include <iostream>
27 #include <vector>
28 
29 #include "aossl/core/include/buffers.h"
30 #include "aossl/core/include/kv_store_interface.h"
31 
32 #include "aossl/consul/include/consul_interface.h"
33 #include "aossl/uuid/include/uuid_interface.h"
34 
35 #include "aossl/commandline/include/factory_cli.h"
36 #include "aossl/properties/include/factory_props.h"
37 #include "aossl/consul/include/factory_consul.h"
38 #include "aossl/uuid/include/factory_uuid.h"
39 
40 #include "aossl/vault/include/vault_interface.h"
41 #include "aossl/vault/include/factory_vault.h"
42 
43 #ifndef AOSSL_PROFILE_INCLUDE_APP_PROFILE_H_
44 #define AOSSL_PROFILE_INCLUDE_APP_PROFILE_H_
45 
46 namespace AOSSL {
47 
49 
54  PropertyReaderFactory props_factory;
55  ConsulComponentFactory consul_factory;
56  UuidComponentFactory uuid_factory;
57  VaultComponentFactory vault_factory;
58  VaultInterface *vault = nullptr;
59  KeyValueStoreInterface *cli = NULL;
60  KeyValueStoreInterface *cfile = NULL;
61  ConsulInterface *consul = NULL;
62  UuidInterface *uuid = NULL;
63  std::string application_name;
64  std::string profile_name;
65 
66  public:
68  ApplicationProfile(int argc, char* argv[]) {
69  cli = cli_factory.get_command_line_interface(argc, argv);
70  uuid = uuid_factory.get_uuid_interface();
71  }
72 
74  ApplicationProfile(int argc, char* argv[], std::string app_name, \
75  std::string prof_name) {
76  cli = cli_factory.get_command_line_interface(argc, argv);
77  uuid = uuid_factory.get_uuid_interface();
78  application_name.assign(app_name);
79  profile_name.assign(prof_name);
80  }
81 
83  explicit ApplicationProfile(const std::vector<std::string>& args) {
84  cli = cli_factory.get_command_line_interface(args);
85  uuid = uuid_factory.get_uuid_interface();
86  }
87 
89  ApplicationProfile(const std::vector<std::string>& args, \
90  std::string app_name, std::string prof_name) {
91  cli = cli_factory.get_command_line_interface(args);
92  uuid = uuid_factory.get_uuid_interface();
93  application_name.assign(app_name);
94  profile_name.assign(prof_name);
95  }
96 
98  ApplicationProfile(std::string app_name, std::string prof_name) {
99  uuid = uuid_factory.get_uuid_interface();
100  application_name.assign(app_name);
101  profile_name.assign(prof_name);
102  }
103 
104  virtual inline ~ApplicationProfile() {
105  if (cli) {delete cli;}
106  if (cfile) {delete cfile;}
107  if (consul) {delete consul;}
108  if (uuid) {delete uuid;}
109  }
110 
112  inline void set_property_file(std::string& filename) {
113  if (cfile) {
114  delete cfile;
115  cfile = NULL;
116  }
117  cfile = props_factory.get_properties_reader_interface(filename);
118  }
119 
121  inline void set_consul_address(std::string caddr) {
122  if (consul) {
123  delete consul;
124  consul = NULL;
125  }
126  consul = consul_factory.get_consul_interface(caddr);
127  }
128 
130  inline void set_consul_address(std::string caddr, int tout, std::string ssl_cert) {
131  if (consul) {
132  delete consul;
133  consul = NULL;
134  }
135  consul = consul_factory.get_consul_interface(caddr, tout, ssl_cert);
136  }
137 
139  inline void set_consul_address(std::string caddr, int tout, std::string ssl_cert, std::string acl_token) {
140  if (consul) {
141  delete consul;
142  consul = NULL;
143  }
144  consul = consul_factory.get_consul_interface(caddr, tout, ssl_cert, acl_token);
145  }
146 
148  inline void set_vault_address(std::string& vaddr, std::string& secrets_path, \
149  int tout, std::string& cert, int auth_type, std::string& un, std::string& pw) {
150  if (vault) {
151  delete vault;
152  vault = nullptr;
153  }
154  vault = vault_factory.get_vault_interface(vaddr, secrets_path, 5, cert, auth_type, un, pw);
155  }
156 
158  inline void set_vault_address(std::string& vaddr, std::string& secrets_path, \
159  int tout, int auth_type, std::string& un, std::string& pw) {
160  if (vault) {
161  delete vault;
162  vault = nullptr;
163  }
164  vault = vault_factory.get_vault_interface(vaddr, secrets_path, 5, auth_type, un, pw);
165  }
166 
169 
172 
174  ConsulInterface* get_consul() {return consul;}
175 
177  VaultInterface* get_vault() {return vault;}
178 
180  UuidInterface* get_uuid() {return uuid;}
181 
183  std::string get_app_name() {return application_name;}
184 
186  std::string get_profile_name() {return profile_name;}
187 
189  void set_app_name(std::string name) {application_name.assign(name);}
190 
192  void set_profile_name(std::string prof) {profile_name.assign(prof);}
193 };
194 
195 } // namespace AOSSL
196 
197 #endif // AOSSL_PROFILE_INCLUDE_APP_PROFILE_H_
KeyValueStore * get_properties_reader_interface(std::string filename)
Get a Properties File Interface Instance.
Definition: factory_props.h:50
std::string get_profile_name()
Get the Profile Name.
Definition: app_profile.h:186
Application Session which manages configuration elements.
Definition: app_profile.h:52
UUID Admin.
Definition: uuid_interface.h:40
The UUID Service Component Factory.
Definition: factory_uuid.h:39
void set_consul_address(std::string caddr, int tout, std::string ssl_cert)
Set the address of the consul agent.
Definition: app_profile.h:130
ApplicationProfile(int argc, char *argv[], std::string app_name, std::string prof_name)
Create a new Application Session with Command Line Arguments.
Definition: app_profile.h:74
void set_app_name(std::string name)
Get the Application Name.
Definition: app_profile.h:189
VaultInterface * get_vault()
Get the Vault Interface.
Definition: app_profile.h:177
KeyValueStoreInterface * get_cli()
Get the Command Line Interface.
Definition: app_profile.h:168
std::string get_app_name()
Get the Application Name.
Definition: app_profile.h:183
KeyValueStore * get_command_line_interface(int argc, char *argv[])
Get the Command Line Interface instance.
Definition: factory_cli.h:50
void set_profile_name(std::string prof)
Get the Profile Name.
Definition: app_profile.h:192
The Consul Administrator, who handles configuration & service discovery.
Definition: consul_interface.h:115
ApplicationProfile(const std::vector< std::string > &args)
Create a new Application Session with Command Line Arguments.
Definition: app_profile.h:83
void set_consul_address(std::string caddr)
Set the address of the consul agent.
Definition: app_profile.h:121
UuidInterface * get_uuid_interface()
Get the UUID Interface instance.
Definition: factory_uuid.h:48
void set_vault_address(std::string &vaddr, std::string &secrets_path, int tout, int auth_type, std::string &un, std::string &pw)
Update the Vault connectivity information.
Definition: app_profile.h:158
The Consul Service Component Factory.
Definition: factory_consul.h:44
void set_vault_address(std::string &vaddr, std::string &secrets_path, int tout, std::string &cert, int auth_type, std::string &un, std::string &pw)
Update the Vault connectivity information.
Definition: app_profile.h:148
UuidInterface * get_uuid()
Get the UUID Interface.
Definition: app_profile.h:180
ApplicationProfile(const std::vector< std::string > &args, std::string app_name, std::string prof_name)
Create a new Application Session with Command Line Arguments.
Definition: app_profile.h:89
Key Value Store.
Definition: kv_store_interface.h:38
ApplicationProfile(int argc, char *argv[])
Create a new Application Session with Command Line Arguments.
Definition: app_profile.h:68
ConsulInterface * get_consul()
Get the Consul Interface.
Definition: app_profile.h:174
KeyValueStoreInterface * get_props()
Get the Properties File Reader.
Definition: app_profile.h:171
ConsulInterface * get_consul_interface(std::string caddr)
Get a Consul Interface instance.
Definition: factory_consul.h:53
The Property File Reader Service Component Factory.
Definition: factory_props.h:40
The Command Line Interpreter Service Component Factory.
Definition: factory_cli.h:41
void set_property_file(std::string &filename)
Set the location of the properties file.
Definition: app_profile.h:112
ApplicationProfile(std::string app_name, std::string prof_name)
Create a new Application Session without any Command Line Arguments.
Definition: app_profile.h:98
void set_consul_address(std::string caddr, int tout, std::string ssl_cert, std::string acl_token)
Set the address of the consul agent.
Definition: app_profile.h:139
Definition: cli.h:35