@naanlang/naan 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,7 +47,11 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
47
47
  {
48
48
  label: "Bucket"
49
49
  placeholder: "e.g. myBucketName"
50
- key: "bucketName" }
50
+ key: "bucketName" },
51
+ {
52
+ label: "Endpoint"
53
+ placeholder: "custom URL"
54
+ key: "endpoint" }
51
55
  ]
52
56
  }
53
57
 
@@ -59,6 +63,7 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
59
63
  `(error, creds) = connector.vault.accessResource(resID)
60
64
  if creds && (!resource.region || resource.region == creds.region)
61
65
  && (!resource.bucketName || resource.bucketName == creds.bucketName)
66
+ && (!resource.endpoint || resource.endpoint == creds.endpoint)
62
67
  && (!resource.label || resource.label == creds.label)
63
68
  return (resID)
64
69
  }
@@ -75,6 +80,7 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
75
80
  // keySecret - AWS IAM keySecret
76
81
  // region - AWS region
77
82
  // bucketName - AWS bucketName
83
+ // endpoint - custom URL
78
84
  // hidden - [optional] don't enumerate to user
79
85
  // locked - [optional] don't allow user delete
80
86
  // The return value is an (error, resID) tuple. Error, if non-false, is a dictionary of field
@@ -90,6 +96,8 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
90
96
  region: resource.region,
91
97
  bucketName: resource.bucketName
92
98
  }
99
+ if resource.endpoint
100
+ creds.endpoint = resource.endpoint
93
101
  errors = { }
94
102
  if resource.label
95
103
  creds.label = resource.label
@@ -107,6 +115,8 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
107
115
  errors.region = "required field"
108
116
  if badField(resource.bucketName)
109
117
  errors.bucketName = "required field"
118
+ if resource.endpoint && badField(resource.endpoint)
119
+ errors.endpoint = "invalid field"
110
120
  if length(errors) > 0
111
121
  error = errors
112
122
  else {
@@ -164,6 +174,8 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
164
174
  resource.region = creds.region
165
175
  if string(creds.bucketName)
166
176
  resource.bucketName = creds.bucketName
177
+ if string(creds.endpoint)
178
+ resource.endpoint = creds.endpoint
167
179
  list(false, resource)
168
180
  }
169
181
 
@@ -209,22 +221,28 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
209
221
  //
210
222
  // Return an S3 access object, which is the credentials to access an AWS S3 bucket.
211
223
 
212
- connector.access = function access(resID, local error, creds, s3b) {
224
+ connector.access = function access(resID, local error, creds, params, s3b) {
213
225
  `(error, creds) = connector.vault.accessResource(resID)
214
226
  if error
215
227
  return (list(error)) // can't access that resource
216
228
  if !awsSDK.S3
217
229
  return (list(Error("S3 connector: no AWS SDK available")))
230
+ params = {
231
+ region: creds.region
232
+ credentials: {
233
+ accessKeyId: creds.keyID
234
+ secretAccessKey: creds.keySecret
235
+ }
236
+ }
218
237
  s3b = {
219
- s3: xnew(awsSDK.S3, {
220
- region: creds.region
221
- credentials: {
222
- accessKeyId: creds.keyID
223
- secretAccessKey: creds.keySecret
224
- }})
225
238
  bucketName: creds.bucketName
226
239
  region: creds.region
227
240
  }
241
+ if creds.endpoint {
242
+ params.endpoint = creds.endpoint
243
+ s3b.endpoint = creds.endpoint
244
+ }
245
+ s3b.s3 = xnew(awsSDK.S3, params)
228
246
  list(false, s3b)
229
247
  }
230
248
 
@@ -232,10 +250,11 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
232
250
  //
233
251
  // Connect to an AWS bucket filesystem, returning a view.
234
252
 
235
- connector.connect = function connect(resID, service, args, local error, s3b, db, table) {
253
+ connector.connect = function connect(resID, service, args,
254
+ local error, s3b, db, rootpath, table) {
236
255
  `(error, s3b) = connector.access(resID)
237
256
  if !error
238
- `(error, db) = S3DB(s3b) // get S3 bucket as a database
257
+ `(error, db) = S3DB(s3b, args.1) // get S3 bucket as a database
239
258
  if error
240
259
  list(error)
241
260
  else if service == "NideDB"
@@ -244,7 +263,7 @@ closure psmaConnector(psm, local connClassID, connector, watch) {
244
263
  rootpath = args.0 // connect to a NideFS filesystem
245
264
  if !rootpath
246
265
  return (Error("mandatory rootpath missing"))
247
- `(error, table) = db.table(rootpath)
266
+ `(error, table) = db.table(rootpath, args.1) // args.1 is table options; see dawsTable
248
267
  if error
249
268
  list(error)
250
269
  else
@@ -26,10 +26,8 @@ function sawsInit(local manifest) {
26
26
  require("frameworks/common").LiveImport()
27
27
  require("./aws_utils.nlg")
28
28
  function sawsPostload() {
29
- if js.lambda
30
- awsSDK = js.r("/opt/aws-sdk-node.min.js") // SDK is a layer
31
- else if js.g
32
- awsSDK = js.r("aws-sdk-node.min") // SDK must be in search path
29
+ if js.g
30
+ awsSDK = js.r(JSpath.join(js.d, module.locpath, "./aws/aws-sdk-node.min.js"))
33
31
  else
34
32
  awsSDK = JsLoadScript(JSpath.join(module.locpath, "./aws/aws-sdk.min.js"), "awsSdk")
35
33
  module.exports.awsSDK = awsSDK