-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWSWorkbench_Main.php
92 lines (74 loc) · 2.38 KB
/
AWSWorkbench_Main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
require_once dirname(__FILE__) . '/interface/AWSWorkbench_Interface.php';
require_once dirname(__FILE__) . '/services/WP_Lex_Chatbot_Data_Service.php';
class AWSWorkbench_Main {
public $API_KEY;
public $API_SECRET;
public $AWS_SDK;
public $IS_CONFIGURED = false;
public $AWS_S3;
public $AWS_SES;
public $AWS_LEX_MODEL;
public $AWS_LEX_RUNTIME;
public $AWS_ROUTE53;
public $AWS_ROUTE53_DOMAINS;
public function __construct () {
}
public function init ($file) {
$AWS_INTERFACE = new AWSWorkbench_Interface();
$AWS_INTERFACE->init();
$this->load_credentials();
$this->instantiate_sdk_client();
$this->test_sdk_configuration();
$this->register_lex_model_client();
$this->register_lex_runtime_client();
$this->initialize_database_tables($file);
}
public static function return_credentials () {
return get_option('aws_workbench_credentials');
}
private function load_credentials () {
$credentials = get_option('aws_workbench_credentials');
if (isset($credentials)) {
$this->API_KEY = $credentials['API_KEY'];
$this->API_SECRET = $credentials['API_SECRET'];
}
}
private function instantiate_sdk_client () {
if (isset($this->API_KEY) && isset($this->API_SECRET) ){
require AWS_WORKBENCH_DIR . '/aws/aws-autoloader.php';
$credentials = new Aws\Credentials\Credentials($this->API_KEY, $this->API_SECRET);
$shared_config = [
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => $credentials
];
$sdk = new Aws\Sdk($shared_config);
$this->AWS_SDK = $sdk;
}
}
private function initialize_database_tables ($file) {
error_log('Main initialize_database_tables getting called');
register_activation_hook($file, array('WP_Lex_Chatbot_Data_Service', 'initialize_plugin_tables'));
}
private function test_sdk_configuration () {
try {
$s3 = $this->AWS_SDK->createS3();
$s3->listBuckets();
$this->IS_CONFIGURED = true;
}
catch (Exception $exc) {
echo $exc;
$this->IS_CONFIGURED = false;
}
}
public function register_lex_model_client () {
$this->AWS_LEX_MODEL = $this->AWS_SDK->createLexModelBuildingService();
}
public function register_lex_runtime_client () {
$this->AWS_LEX_RUNTIME = $this->AWS_SDK->createLexRuntimeService();
}
}