How to use Travis CI Environment Variable to set Meteor.settings? - meteor

How do I use Travis CI environment variables to set API keys in Meteor.settings? I've tried adding a new environment variable named METEOR_SETTINGS with:
'{
"facebook_keys": {
"app_id": "1234567890",
"app_secret": "1234567890"
},
"instagram_keys": {
"client_id": "1234567890",
"client_secret": "1234567890",
"access_token": "1234567890"
}
}'
but I get the following error: TypeError: Cannot read property 'app_id' of undefined. All tests are running fine except the ones using Meteor.settings.

Related

Deno cotton 'must have type'

I'm following a course on Deno and Angular but I am stuck. I have even downloaded the final code supplied by the person who created the course and get the same type of error.
When I try and run this commmand: deno run --allow-net --unstable app.ts
I keep getting this error message:
Check file:///?:/????/deno-admin-main/app.ts
error: Uncaught Error: Column 'role_id' must have a type!
throw new Error(Column '${propertyKey}' must have a type!);
^
at https://deno.land/x/cotton#v0.7.5/src/model.ts:76:13
at DecorateProperty (https://deno.land/x/cotton#v0.7.5/src/utils>/reflect.ts:1431:27)
at Reflect.decorate (https://deno.land/x/cotton#v0.7.5/src/utils/reflect.ts:858:16)
at __decorate (file:///?:/????/deno-admin-main/src/models/role-permission.ts:3:92)
at file:///?:/????/deno-admin-main/src/models/role-permission.ts:9:5
// role-permission
import {Model, Primary, Column} from "https://deno.land/x/cotton#v0.7.5/mod.ts";
#Model('role_permissions')
export class RolePermission {
#Primary()
id!: number;
#Column()
role_id!: number;
#Column()
permission_id!: number;
}
According to their docs the use of this cotton feature requires a custom tsconfig.json to be included when running the program:
Keep in mind that this feature requires a custom TypeScript configuration to tell Deno that we want to use TypeScript decorators (opens new window), which is currently still an experimental feature.
// tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
deno run --unstable --config ./tsconfig.json app.ts
The problem was a typo. I did not add "app.ts" to the file scripts.json:
{
"$schema": "https://deno.land/x/denon#2.4.7/schema.json",
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "run my app.ts file",
"allow": [
"net"
] ,
"tsconfig": "tsconfig.json"
}
},
"watcher": {
"match": [
"app.ts",
"src/**/*.ts"
]
}
}

pushsubscription gives options instead of keys when using requestSubscription()

I'm trying to follow this tutorial to enable push notifications in my PWA. According to the tutorial, I should get a pushSubscription object like this:
{
"endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
"expirationTime": null,
"keys": {
"p256dh": "BOXYnlKnMkzlMc6xlIjD8OmqVh-YqswZdut2M7zoAspl1UkFeQgSLYZ7eKqKcx6xMsGK7aAguQbcG9FMmlDrDIA=",
"auth": "if-YFywyb4g-bFB1hO9WMw=="
}
}
However when I inspect my subscription object I get something in the form of
{
"endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
"expirationTime": null,
"options": {
"applicationServerKey": ArrayBuffer(65),
"userVisibleOnly": true
}
}
note that I do not get the keys object and instead get an options object.
Have the properties of the pushSubscription object changed? If I use this to send notifications, will it still work?
When saving my pushSubscription object with Mongoose, I used keys instead of options
If I then inspect the object in my db (on MLab in my case) it looks like
{
"endpoint": "https://fcm.googleapis.com/fcm/send/cbx2QC6AGbY:APA91bEjTzUxaBU7j-YN7ReiXV-MD-bmk2pGsp9ZVq4Jj0yuBOhFRrUS9pjz5FMnIvUenVqNpALTh5Hng7HRQpcUNQMFblTLTF7aw-yu1dGqhBOJ-U3IBfnw3hz9hq-TJ4K5f9fHLvjY",
"expirationTime": null,
"keys": {
"p256dh": "BOXYnlKnMkzlMc6xlIjD8OmqVh-YqswZdut2M7zoAspl1UkFeQgSLYZ7eKqKcx6xMsGK7aAguQbcG9FMmlDrDIA=",
"auth": "if-YFywyb4g-bFB1hO9WMw=="
}
}
I guess that the object in my console is visualized differently, thus showing me the options parameter instead of keys.

Cannot get req.path and req.query.abc with firebase functions

I'm trying to get the request query params and url in firebase functions.
Here is the code I'm using
firebase.json
{
"hosting": {
"public": "build",
"rewrites": [{
"source": "/getCoins",
"function": "getCoins"
}]
}
}
Using "firebase-functions": "^2.3.1" in package.json
functions/index.js
'use strict';
const functions = require('firebase-functions');
exports.getCoins = functions.https.onRequest((req, res) => {
console.log(req.query); // [object Object]
console.log(req.query.repeat); // empty
console.log(req.url); // '/'
console.log(req.originalUrl); // '/'
res.sendStatus(200);
});
Started the firebase functions in my windows command prompt using firebase serve --only functions. As it starts serving data from http://localhost:5000, I'm trying to request http://localhost:5000/coins-app/us-central1/getCoins?repeat=4
I'm not getting any error in the command prompt, but could only see the commented lines from the above functions/index.js code.
You should run firebase serve and request to http://localhost:5000/getCoins?repeat=4 .
functions.https.onRequest() can't accept query string parameter directly.

DynamoDb documentClient.update or delete StringSet throws ValidationException

I successfully update and delete an item from a StringSet in a dynamoDb table when called from my test app running on localhost.
I then upload the app to LightSail but now when I call the same function to update or delete an item it throws a ValidationException!:
{
"message": "Invalid UpdateExpression: Incorrect operand type for operator or
function; operator: DELETE, operand type: MAP",
"code": "ValidationException",
"time": "2018-01-03T13:20:14.919Z",
"requestId": "9HCQMH5RAUBRK1K7BNESNBUD5BVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 10.381373865940402
}
Why? I have not made any changes to my code so why does this happen and how to solve it?
Here's the relevant code:
var documentClient = getDocumentClient();
var paramsSET = {
ExpressionAttributeNames:
{
"#StringSet": "Packages"
},
ExpressionAttributeValues:
{
":value": documentClient.createSet(['filler as SET cannot be empty',
app.packageName
])
},
Key:
{
"EmailAddress": app.emailAddress
},
ReturnValues: "ALL_NEW",
TableName: "Developers",
UpdateExpression: "ADD #StringSet :value"
// UpdateExpression: "DELETE #StringSet :value" ------ to delete value
};
// adds packagename to Packages SET in developers table - creates set if not exist
documentClient.update(paramsSET, function (err, data){}
I could not get it to work using the documentclient api.
finally used the old api and got it to work using dynamodb.updateItem see docs here
still have no idea why it works on localhost (accessing the same dynamodb tables) and not when live on LightSail!

Elasticsearch - Get locale specific date in Groovy script

I need to update existing documents of a particular type with a new field. This new field should be set to the local day name of a date given by a datetime field in the document. The date time field is in the format yyyy-MM-dd'T'HH:mm:ss, is in UTC but has no explicit timezone code.
I'd like to do this with Groovy but have no Java experience. I'm guessing I need to:
1) Set the datetime to UTC locale
2) Convert to local locale (set to Europe/London) in this case
3) Get the day name from converted date and set new field (dayname) value with it
If I use the following update_by_query:
POST /myindex/_update_by_query
{
"script": {
"inline": "ctx._source.dayname = Some_function(ctx._source.datetime)"
},
"query": {
"term": {
"_type": "myDocType"
}
}
}
Is there a simple way to do this with a some Groovy functions (replacing Some_function above).
Any hints would be very much appreciated!
UPDATE - Thanks to tim_yates i have the following Sense console code:
POST /rating/_update_by_query
{
"script": {
"inline": "ctx._source.day = Date.parse(\"yyyy-MM-dd'T'HH:mm:ss\", ctx._source.datetime, java.util.TimeZone.getTimeZone('UTC')).format('EEEE', java.util.TimeZone.getTimeZone('Europe/London'))"
},
"query": {
"term": {
"_type": "transaction"
}
}
}
Unfortunately this generates the following error message:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "failed to run inline script [ctx._source.day = Date.parse(\"yyyy-MM-dd'T'HH:mm:ss\", ctx._source.datetime, java.util.TimeZone.getTimeZone('UTC')).format('EEEE', java.util.TimeZone.getTimeZone('Europe/London'))] using lang [groovy]"
}
],
"type": "script_exception",
"reason": "failed to run inline script [ctx._source.day = Date.parse(\"yyyy-MM-dd'T'HH:mm:ss\", ctx._source.datetime, java.util.TimeZone.getTimeZone('UTC')).format('EEEE', java.util.TimeZone.getTimeZone('Europe/London'))] using lang [groovy]",
"caused_by": {
"type": "missing_property_exception",
"reason": "No such property: java for class: 1209ff7fb16beac3a71ff2a276ac2225f7c4505b"
}
},
"status": 500
}
Though it does work if I remove reference to the getTimeZone - exact Sense console code as follows:
POST /rating/_update_by_query
{
"script": {
"inline": "ctx._source.day = Date.parse(\"yyyy-MM-dd'T'HH:mm:ss\", ctx._source.datetime).format('EEEE')"
},
"query": {
"term": {
"_type": "transaction"
}
}
}
I'm not sure why the getTimeZone method is failing. I've tried "TimeZone.getTimeZone" instead of "java.util.TimeZone.getTimeZone"
The Groovy code (for Java 7) you will need is going to be very similar to this:
Date.parse("yyyy-MM-dd'T'HH:mm:ss", ctx._source.datetime, TimeZone.getTimeZone('UTC'))
.format('EEEE', TimeZone.getTimeZone("Europe/London"))
OK, a bit more research allowed me to understand that tim_yates answer was correct, we just needed to whitelist the Java class required. We did this via:
nano $JAVA_HOME/lib/security/java.policy
and adding:
permission org.elasticsearch.script.ClassPermission "java.util.TimeZone";
...then restart the ES services.
Note this whitelists the class for all users, not just the ES user. See:
https://www.elastic.co/guide/en/elasticsearch/reference/2.2/modules-scripting-security.html

Resources