forked from cuongquay/node-red-contrib-aws-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-sdk.html
246 lines (233 loc) · 8.38 KB
/
aws-sdk.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!--
Copyright 2013, 2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="aws-sdk-config">
<div class="form-row">
<ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-aws-config-tabs"></ul>
</div>
<div id="node-config-aws-config-tabs-content" style="min-height: 170px;">
<div id="aws-config-tab-connection" style="display:none">
<div class="form-row node-input-name">
<label for="node-config-input-name"><i class="fa fa-globe"></i> <span>Name</span></label>
<input class="input-append-left" type="text" id="node-config-input-name" placeholder="Enter a configuration name" style="width: 40%;" >
</div>
<div class="form-row node-input-access-key">
<label for="node-config-input-access-key"><i class="fa fa-link"></i> <span>Access Key</span></label>
<input class="input-append-left" type="text" id="node-config-input-access-key" placeholder="AWS Access Key" style="width: 40%;" >
</div>
<div class="form-row node-input-secret-key">
<label for="node-config-input-secret-key"><i class="fa fa-edit"></i> <span>Secret Key</span></label>
<input type="number" id="node-config-input-secret-key" placeholder="AWS Secret Key" style="width: 40%;">
</div>
<div class="form-row">
<label for="node-config-input-region"><i class="fa fa-empire"></i> <span>Region</span></label>
<select id="node-config-input-region" style="width:225px !important">
<option value="us-east-1">US East (N. Virginia)</option>
<option value="us-west-2">US West (Oregon)</option>
<option value="us-west-1">US West (N. California)</option>
<option value="eu-west-1">EU (Ireland)</option>
<option value="eu-central-1">EU (Frankfurt)</option>
<option value="ap-southeast-1">Asia Pacific (Singapore)</option>
<option value="ap-northeast-1">Asia Pacific (Tokyo)</option>
<option value="ap-southeast-2">Asia Pacific (Sydney)</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-config-input-iamrole" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-iamrole" style="width: auto;" >Use Base IAM Role Setting</label>
</div>
</div>
<div id="aws-config-tab-about" style="display:none">
<div class="form-row node-label-author">
<label><i class="fa fa-user"></i> <span>Author</span></label>
<span class="input-append-left" style="width: 40%;" >Duong Dinh Cuong</span>
</div>
<div class="form-row node-label-email">
<label><i class="fa fa-email"></i> <span>Email</span></label>
<span class="input-append-left" style="width: 40%;" >[email protected]</span>
</div>
</div>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-sdk-config', {
category : 'config',
defaults : {
name : {
value : ""
},
accesskey : {
value : ""
},
secretkey : {
value : ""
},
region : {
value : ""
},
iamrole: {
value: true
}
},
label : function() {
return (this.name ? this.name: "Default");
},
oneditprepare : function() {
var tabs = RED.tabs.create({
id : "node-config-aws-config-tabs",
onchange : function(tab) {
$("#node-config-aws-config-tabs-content").children().hide();
$("#" + tab.id).show();
}
});
tabs.addTab({
id : "aws-config-tab-connection",
label : "AWS Credentials"
});
tabs.addTab({
id : "aws-config-tab-about",
label : "About"
});
setTimeout(function() {
tabs.resize();
}, 0);
}
});
</script>
<script type="text/x-red" data-template-name="aws sdk">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Enter a name">
</div>
<div class="form-row">
<label for="node-input-config"><span>Configuration</span></label>
<input type="text" id="node-input-config" placeholder="Enter configuration name">
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-func"><i class="fa fa-wrench"></i> <span>Function</span></label>
<input type="hidden" id="node-input-func" autofocus="autofocus">
<input type="hidden" id="node-input-noerr">
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px;" class="node-text-editor" id="node-input-func-editor" ></div>
</div>
<div class="form-row">
<label for="node-input-outputs"><i class="fa fa-random"></i> <span>Outputs</span></label>
<input id="node-input-outputs" style="width: 60px; height: 1.7em;" value="1">
</div>
<div class="form-tips"><span>See the Info tab for help writing functions.</span></div>
</script>
<script type="text/x-red" data-help-name="aws sdk">
<p>A function block where you can write your own code to execute aws-sdk nodejs library.</p>
<p><em>Example of using aws-sdk inside this function block:</em></p>
<p><code>
var s3 = new AWS.S3();<br/>
s3.createBucket({Bucket: 'myBucket'}, function() {<br/>
var params = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'};<br/>
s3.putObject(params, function(err, data) {
msg.payload = data;
callback(msg);
});<br/>
});
</code></p>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws sdk', {
color : "#FFCC66",
category : 'function',
defaults : {
name : {
value : ""
},
func : {
value : "\nreturn msg;"
},
outputs : {
value : 1
},
noerr : {
value : 0,
required : true,
validate : function(v) {
return ((!v) || (v === 0)) ? true : false;
}
},
config : {
type : "aws-sdk-config",
required : true
}
},
inputs : 1,
outputs : 1,
align: "left",
icon : "function.png",
label : function() {
return this.name || "aws sdk";
},
oneditprepare : function() {
var that = this;
$("#node-input-outputs").spinner({
min : 1
});
function functionDialogResize() {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i = 0; i < rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height", height + "px");
that.editor.resize();
}
$("#dialog").on("dialogresize", functionDialogResize);
$("#dialog").one("dialogopen", function(ev) {
var size = $("#dialog").dialog('option', 'sizeCache-function');
if (size) {
$("#dialog").dialog('option', 'width', size.width);
$("#dialog").dialog('option', 'height', size.height);
functionDialogResize();
}
});
$("#dialog").one("dialogclose", function(ev, ui) {
var height = $("#dialog").dialog('option', 'height');
$("#dialog").off("dialogresize", functionDialogResize);
});
this.editor = RED.editor.createEditor({
id : 'node-input-func-editor',
mode : 'ace/mode/javascript',
value : $("#node-input-func").val()
});
RED.library.create({
url : "functions", // where to get the data from
type : "function", // the type of object the library is for
editor : this.editor, // the field name the main text body goes to
mode : "ace/mode/javascript",
fields : ['name', 'outputs']
});
this.editor.focus();
},
oneditsave : function() {
var annot = this.editor.getSession().getAnnotations();
this.noerr = 0;
$("#node-input-noerr").val(0);
for (var k = 0; k < annot.length; k++) {
if (annot[k].type === "error") {
$("#node-input-noerr").val(annot.length);
this.noerr = annot.length;
}
}
$("#node-input-func").val(this.editor.getValue());
delete this.editor;
}
});
</script>