Our company uses Gravitee. I have my ML written in Python. I need to make available via API.
How can I do it? I think I can use FastAPI to expose my code as an API. Will it be possible to "marry" gravitee and my part? Would it be better to use something else instead of FastAPI?
Thanks for any advice
If I understand correctly, yes, you can create an API with FastAPI like:
from fastapi import FastAPI
app = FastAPI()
#app.get("/")
async def root():
# call you ML python code here
return {"message": "It's a cat!"}
Secondly, deploy it somewhere to be able to call your API internally in your company. Which mean that you should call your API like:
$ curl 'http://mlapi.internal.mycompany.com/'
{"message": "It's a cat!"}
And then, register your new API into gravitee like explain here and for example configure the rate limiting to manage your bill related to the resource needed by your ML API ;)
Note that if you also have an Access Management available, you can manage authentication without implementing it.
Hope it's help.
Related
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
Im trying to implement authentication on my SPA, and it works fine.
The way im doing it is like in the docs:
import firebase from 'firebase/app';
import 'firebase/auth';
const config = {
// ...
};
const firebaseApp = firebase.initializeApp(config);
// and somewhere else in the code(with all the arguments and stuff)
firebase.auth().createUserWithEmailAndPassword();
firebase.auth().signInWithEmailAndPassword();
Now, my problem is that these imports add too much to the app. I honestly don't think that 180KB(minified, but not compressed) is acceptable for an SPA that aims to work on mobile.
Just for comparison, my whole app, Vuejs + Router + Vuex + other 3~ small libraries and the app logic weight 170KB(minified but not compressed).
So I wanted to know if there is another solution, or if im doing it wrong, or if there is an easy workaround. Ideally, I would be able to just make an HTTP request and get back a JWP.
Well, I contacted firebase to add this as a feature request, and they suggested me to use for now the REST API for auth. It requires a custom token, but it is a good solution.
The documentation for the REST API:
https://firebase.google.com/docs/reference/rest/auth/
As far as I know, the actual endpoints you hit for Firebase auth isn't publicly documented nor have I seen them around the Web. With that said, if you are set on reducing your bundle size, your best bet is to pick apart the SDK and figure out how and what you need to construct.
signInWithEmailAndPassword is defined here and as you can see, it just calls out to another private function and so on.
I'm using Firebase as a simple game-server and have some settings that are relevant for both client and backend and would like to keep them in RemoteConfig for consistency, but not sure if I can access it from my cloud functions in a simple way (I don't consider going through the REST interface a "simple" way)
As far as I can tell there is no mention of it in the docs, so I guess it's not possible, but does anyone know for sure?
firebaser here
There is a public REST API that allows you to read and set Firebase Remote Config conditions. This API requires that you have full administrative access to the Firebase project, so must only be used on a trusted environment (such as your development machine, a server you control or Cloud Functions).
There is no public API to get Firebase Remote Config settings from a client environment at the moment. Sorry I don't have better news.
This is probably only included in newer versions of firebase (8th or 9th and above if I'm not mistaken).
// We first need to import remoteConfig function.
import { remoteConfig } from firebase-admin
// Then in your cloud function we use it to fetch our remote config values.
const remoteConfigTemplate = await remoteConfig().getTemplate().catch(e => {
// Your error handling if fetching fails...
}
// Next it is just matter of extracting the values, which is kinda convoluted,
// let's say you want to extract `game_version` field from remote config:
const gameVersion = remoteConfigTemplate.parameters.game_version.defaultValue.value
So parameters are always followed by the name of the field that you defined in Firebase console's remote config, in this example game_version.
It's a mouthful (or typeful) but that's how you get it.
Also note that if value is stored as JSON string, you will need to parse it before usage, commonly: JSON.parse(gameVersion).
Similar process is outlined in Firebase docs.