VaporMySQL Provider - vapor

import Vapor
import VaporMySQL
let mysql = try VaporMySQL.Provider(host: "localhost", user: "username", password: "secret", database: "coffeeLedger")
What is the difference between
let drop = Droplet(preparations: [CoffeeLedger.self], providers: [VaporMySQL.Provider.self])
and....
let drop = Droplet(preparations: [CoffeeLedger.self], providers: [mysql])
I get a Cannot convert value of type 'Provider' to expected element type 'Provider.Type' error

providers was renamed to initializedProviders in Vapor 0.16 to make room for ConfigInitializable provider support.
Basically, now you can just pass the Type of the provider and it will attempt to initialize from the configuration files in the Config/ folder.
This style of initialization helps remove magic numbers and strings from the source code, like the host and password.
If you want to keep initializing the provider normally, just use initializedProvider:

Related

write_points() Python not writing data for InfluxDB

I'm doing the basic setup in python to pass data to an InfluxDB server I have running on a RaspberryPi. My issue is the write_points() function does not write ANY data to InfluxDB even though I am using the simplest possible measurement and field-set entry as a test:
from influxdb import InfluxDBClient
from influxdb_config import HOST, PORT, USERNAME, PASSWORD, DATABASE
from data_poll import quotes_response
import pprint
influxdbClient = InfluxDBClient(
host = HOST,
port = PORT,
username = USERNAME,
password = PASSWORD,
database = 'example'
)
data = [
{
"measurement": "stock price",
"fields": {
"price": 0.64,
"volume": 120
}
}
]
pprint.pprint(influxdbClient.ping())
pprint.pprint(influxdbClient.get_list_database())
influxdbClient.switch_database('example')
pprint.pprint(influxdbClient.write_points(data))
pprint.pprint(influxdbClient.query('SELECT * FROM example'))
I am able to communicate with the server via Python and, if I create values manually on the server, retrieve them in the same script. Below is a snippet of the terminal output that matches some of the requests in the above code snippet.
'1.8.4'
[{'name': '_internal'}, {'name': 'jsonAAPLDataTest'}, {'name': 'example'}]
True
ResultSet({})
Update 2021/03/14 - I'm currently using Python 3.9.2, but had the exact same issue utilizing 3.7.3 (tested by the API developers). My next attempt is to downgrade my InfluxDB instance from v1.8.4 to v1.7.4 to see if this, by chance, resolves the issue.
I was able to now right data to my InfluxDB v1.8.4 database using the proper API github.com/influxdata/influxdb-client-python. Prior to this I was utilizing the prior release API which apparentely must have a difference in the underlying functionality of writing to the database. FIgured I would at least follow up and share the information so others would know in case they encoutner this issue.

Is passing environment variables to sapper's client side secure with Rollup Replace?

I am using replace in my rollup configuration for sapper and sapper-environment to pass environment variables to the client side in sapper - is this secure? Is there a better/safer way to approach this?
Using this config below:
rollup.config.js
const sapperEnv = require('sapper-environment');
export default {
client: {
input: config.client.input(),
output: config.client.output(),
plugins: [
replace({
...sapperEnv(),
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode)
})
...
And then this allows me to use the variables in stores.js:
import { writable } from 'svelte/store';
import Client from 'shopify-buy';
const key = process.env.SAPPER_APP_SHOPIFY_KEY;
const domain = process.env.SAPPER_APP_SHOPIFY_DOMAIN;
// Initialize a client
const client = Client.buildClient({
domain: domain,
storefrontAccessToken: key
});
export { key, domain, client };
I have tried running this in server,js and passing the variables through the session data, but client side no matter what I do they always seems to return 'undefined'.
There are two questions here — a) is it secure, and b) why are the values undefined?
The answer to the first question is 'no'. Any time you include credentials in JavaScript that gets served to the client (or in session data), you're making those credentials available to anyone who knows how to look for them. If you need to avoid that, you'll need your server (or another server) to make requests on behalf of authenticated clients.
As for the second part, it's very hard to tell without a reproduction unfortunately!

How to set up Watson ConversationService in F#

Initializing the ConversationService() object in C# if fairly straightforward, but I'm having issues doing the same in F#. When I run the code below, I get a Parameter name: versionDate cannot be null. Use 'CONVERSATION_VERSION_DATE_2017_05_26' error.
I've tried manually adding "versionDate": "2017-05-26" and "version_date": "2017-05-26" to the credential string, but it is still producing the same error.
Is there a way I can pass the version date correctly to the ConversationService object to avoid this null pointer exception?
C# Version
ConversationService service = new ConversationService( <username> , <password> , ConversationService.CONVERSATION_VERSION_DATE_2017_05_26);
F# Version
let credential = """
{
"url": "https://gateway.watsonplatform.net/conversation/api",
"username": "xxxxxxxxxxxxxx",
"password": "xxxxxxxxxxxxxx"
}
"""
let workspaceID = "xxxxxxxxxxxxxx"
let service = new ConversationService()
service.SetCredential credential

How does one pull an API environment variable in rails

Implementing in rails and only running locally for the time being.
Using I have a google API server key for google places that is... lets say... "abc123"
When I use a url just to see with a url like:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=abc123
it pulls information.
When I type env from mac terminal I have a value listed that is :
PLACES_API=abc123
when I run the code filling in the literal key:
#client = GooglePlaces::Client.new("abc123")
it works fine.
HOWEVER, when I try and pull this in using
#client = GooglePlaces::Client.new(ENV['PLACES_API'])
it errors out and when I try to puts ENV['PLACES_API'] it is blank.
I am assuming I am not using the env variable correctly, but now I want to know what I am doing wrong and how to use the environmental variable.
OPTION 1
If you are using ENV['PLACES_API'] in your code then before you start rails server you have to export the key. In your terminal run export PLACES_API="api key" and then start the server.
OPTION 2 (A better way to handle secret keys )
create a file gmap.yaml inside config directory with the following code
development:
secret: "api key"
test:
secret: "api key"
production:
secret: "api key"
Now create a new file gmap.rb inside config/initializars directory with the following code
PLACES_API = YAML.load_file("#{::Rails.root}/config/gmap.yml")[::Rails.env]
Now you can access the key with
#client = GooglePlaces::Client.new(PLACES_API['secret'])

Django admin and MongoEngine ObjectID instead of int()

Small test case is https://github.com/mekanix/djangomongodbtest, I can't seem to get admin page to show up. I login and get "int() argument must be a string or a number, not 'ObjectId'" exception. Is django admin used with mongoengine at all or do I have to use something like https://github.com/jschrewe/django-mongoadmin? Thanx!
You may need to update the handler for admin as well. The Django provided handler admin.site.urls does not work with Mongo.
from django.conf.urls import include
from django_mongoengine import mongo_admin
urlpatterns = [
url(r'^admin/', include(mongo_admin.site.urls)),
]

Resources