I'd like to use Google Cloud Datastore from a Rails app. Any Ruby lib that would make that easy?
You can use the official Google API Client for Ruby:
https://github.com/google/google-api-ruby-client
# Log in
google-api oauth-2-login --client-id='...' --client-secret='...' --scope="https://www.googleapis.com/auth/datastore https://www.googleapis.com/auth/userinfo.email"
# Start an interactive API session
google-api irb
>> ds = $client.discovered_api('datastore', 'v1beta1')
>> $client.execute(ds.lookup, {'datasetId' => '...', 'keys' => [...]})
=> # returns a response from the API
There seems to be very little resources on using Datastore with Ruby, but this page is probably the best place to start:
https://cloud.google.com/datastore/docs/getstarted/start_ruby/
Related
I'm trying to require aws sdk database for use in a web application, but I'm getting the following errors
const AWS = require(["aws-sdk"]);
AWS.config.update({ region: "ap-southeast-2" });
AWS.config.update({
region: "{Region[enter image description here][1]}",
// For security reasons, do not store AWS Credentials in your files. Use Amazon Cognito instead.
accessKeyId: "{Key}",
// secretAccessKey default can be used while using the downloadable version of DynamoDB.
// For security reasons, do not store AWS Credentials in your files. Use Amazon Cognito instead.
secretAccessKey: "{Key}"
});
You're using the wrong syntax, passing an array to require is part of the callback syntax and expects a function as a second argument.
Try this instead:
const AWS = require("aws-sdk");
Also, I'm not sure why you're calling config.update twice, you probably should just do it once to avoid any issues, or at a minimum to avoid confusion.
I want to verify if a user exists in the Authentication list of users in firebase. I know I can use:
admin.auth().getUserByEmail(email)
admin.auth().getUser(uid)
I am building a react native app, so I can't install firebase-admin since it would require I ship credentials in the app, which is too dangerous, since someone can do reverse engineering and find them.
I have found I can write functions, so I have created a separate project to create and deploy functions, this will work as a backend.
Now I want to create a function there that uses firebase-admin and to be able to use the 2 methods listed above.
I found I can create:
exports.addMessage = functions.https.onCall((data, context) => {
// ...
});
and call it like:
var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({text: messageText}).then(function(result) {
// Read result of the Cloud Function.
});
Not sure if using https.onCall is the best for this case or is there a better way.
Thanks in advance.
As far as the documentation indicates - accessible here - and the fact that the https.onCall() uses a safe method to be called (HTTPS) I believe that this is the best option for your case, since installing firebase-admin doesn't fit your case.
The official documentation Protocol specification for https.onCall also says:
If you are able to use the Android, iOS, or web SDKs, you're recommended to do that instead of directly implementing this protocol. The SDKs provide features to save coding time and effort, as detailed in Call Functions from Your App
So, this is indicated, in case you don't want/can use the SDK, which I believe it's what you are saying. Considering that, I believe that the https.onCall() it's the option for your situation.
Let me know if the information helped you!
I'm working on putting together a server-side Dart application that will run in App Engine. It needs to access a Firestore database, but I'm having trouble doing so.
The Dart packages I've tried are:
firebase_admin_interop
firebase
In both cases, I get errors like this when attempting to execute my code:
file:///root/.pub-cache/hosted/pub.dartlang.org/firebase_admin_interop-1.2.2/lib/src/database.dart:5:8: Error: Not found: 'dart:js'
import 'dart:js';
My vague understanding of this error is that it means the library has a dependency on running in a browser. However, I've not been able to find any way to interact with Firestore in a server-to-server configuration using Dart.
Is my only recourse here to use the Firestore REST API?
There is no Firebase Admin SDK for Dart. So indeed the REST API would be your best best.
Note that much of the Admin functionality is not exposed in documented REST API. So ymmv, and I'd seriously consider switching to a platform where you can use one of the official Admin SDKs.
If the number of search results on google are an indicator for popularity, then
Go, Node.js and C# are the languages most people use with the firestore admin libraries
Google searched input taken from https://cloud.google.com/firestore/docs/quickstart-servers
Go: "cloud.google.com/go/firestore" -> 3890 results
Node.js: "require('#google-cloud/firestore')" -> 2120 results
C#: "FirestoreDb.Create" -> 1110
Python: "from google.cloud import firestore" -> 859 results
Java: "import com.google.cloud.firestore.Firestore" -> 601 results
PHP: "Google\Cloud\Firestore\FirestoreClient" -> 1 result
I am looking for a tutorial or document on how to access datastore using cloud functions (python).
However, it seems there is only tutorial for nodejs.
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore
Can anybody help me out?
Thanks
There are no special setup needed to access datastore from cloud functions in python.
You just need to add google-cloud-datastore into requirements.txt and use datastore client as usual.
requirements.txt
# Function dependencies, for example:
# package>=version
google-cloud-datastore==1.8.0
main.py
from google.cloud import datastore
datastore_client = datastore.Client()
def foo(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values...
"""
query = datastore_client.query(kind=<KindName>)
data = query.fetch()
for e in data:
print(e)
Read more:
Python Client for Google Cloud Datastore
Setting Up Authentication for Server to Server Production Applications
I'm writing a CLI with Go and I want to save the password to a config file that is saved in the user home directory.
Should I encrypt the password on save and decrypt it when sending it to the server the CLI interact with?
And if so, is there a good built in library in go library to do so? I want to keep it as simple as possible and without using any additional outside packages. All the answers I saw was quite complex.
Should be something like this:
func Encrypt(password string) string
func Decrypt(password string) string
Any ideas?
Disclaimer: The core lib does not provide this functionality out of the box. There is a third party lib for Go (from Docker) which can help.
Modern Operating Systems provide tools and APIs to store secrets in a secure way.
Apple: Keychain
Linux: Secret Service
Windows: Credentials Manager API
Git and Docker uses these tools to store your credentials.
David Calavera who contributed Docker credential helpers to Docker Engine v1.11 wrote an article titled Stop saving credential tokens in text files in 2016. The article describes the problem, a simple implementation for Linux and shows how to use the library.
package main
import (
"github.com/docker/docker-credential-helpers/client"
"github.com/docker/docker-credential-helpers/credentials"
)
var nativeStore = client.NewShellProgramFunc("docker-credential-secretservice")
func main() {
c := &credentials.Credentials{
ServerURL: "https://api.github.com",
Username: "token",
Secret: "my-super-secret-token",
}
client.Store(nativeStore, c)
storedCreds, err := client.Get(nativeStore, "https://api.github.com")
}
The drawback of Docker credential helpers is that it expects you to install its binaries and needs CGo. I added the Docker solution specifically because it was mentioned in the comments but there are similar libraries:
99designs/keyring - Originally was part of AWS vault lib.
zalando/go-keyring - A pure Go implementation which goal was to avoid C bindings.