Firebase Admin SDK - Verify ID exists - python

As part of our current API calls we receive the user's firebase installation ID. e.g. ezOi0OrW6UQAuyf9m0MeRq
Is it possible to verify the ID actually exists via the Firebase Admin SDK in Python?
Tried some of the functions regarding users in the SDK docs and kept getting user ID not found. I may be trying it in the wrong place.

decoded_token = auth.verify_id_token(id_token)
uid = decoded_token['uid']
Reference link: https://firebase.google.com/docs/auth/admin/verify-id-tokens#python

Related

GET and POST Function App Function/Host Keys Using Python (Azure Government)

I am attempting to retrieve and add function/host keys for an Azure Government function app via Python. I am currently working with the information from this question and the corresponding API page. While these are not specific to Azure Government, I would think the process would be similar after updating the URLs to the Azure Government versions. However, I am receiving the error "No route registered for '/api/functions/admin/token'" when running the jwt part of the given code. Is this approach feasible for what I am trying to do?
I also found somewhere that I instead might want to try a GET request like this:
resp = requests.get("https://management.usgovcloudapi.net/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Web/sites/<function-app-name>/functions/admin/masterkey?api-version=20XX-XX-XX", headers={"Authorization": f"Bearer {something}"})
This gives me the error "{"error":{"code":"InvalidAuthenticationToken","message":"The access token is invalid."}}", though. If this is indeed the correct approach, then what format should the Bearer token take?
Bit late answering but it may be useful for someone else in the future, it took me a while to find out how to do this.
If you want to retrieve the keys of a specific function within a function app then you can use list_function_keys() function from the Python SDK
Working with the Az management API directly may be a bit annoying and since the Azure CLI is written in Python whatever operation you do with the CLI you can do it directly in a Python script.
Here's an example of how you can retrieve the keys
from azure.identity import DefaultAzureCredential
from azure.mgmt.web import WebSiteManagementClient
# Your subscription ID
SUB_ID = "00000000-0000-0000-0000-000000000000"
fn_name = "some_function" # Name of your function
app_name = "some_app" # Name of your site/function app
rg_name = "some_rg" # Resource group name to which the function belongs
web_client = WebSiteManagementClient(subscription_id=SUB_ID, credential=DefaultAzureCredential())
keys = web_client.web_apps.list_function_keys(rg_name, app_name, fn_name)
# Your keys will be accessible in the additional_properties param
print(keys.additional_properties)
Hope it helps! I'm new on Azure so if I'm doing something wrong, please don't hesitate to point out my mistake and share your correction

Google Cloud Storage - How to retrieve a file's owner via Python?

I'm trying to access to a blob uploaded on a bucket of Google Cloud Storage via Python official client (google-cloud-storage).
I'm managing into retrieving the owner of the file (the one who uploaded it), and I'm not finding something useful on internet.
I've tried using the client with something like:
client(project='project').get_bucket('bucket').get_blob('blob')
But the blob properties like "owner" are empty!
So I tried using a Cloud Function and accessing to event and context.
In the Google documentation (https://cloud.google.com/storage/docs/json_api/v1/objects#resource) it is reported the structure of an event and it seems to have the owner propriety. But when I print or try to access it I obtain an error because it is not set.
Can someone help me? I just need to have the user email... thanks in advance!
EDIT:
It doesn't seem to be a permission error, because I obtain the correct results testing the API from the Google site: https://cloud.google.com/storage/docs/json_api/v1/objects/get?apix_params=%7B%22bucket%22%3A%22w3-dp-prod-technical-accounts%22%2C%22object%22%3A%22datagovernance.pw%22%2C%22projection%22%3A%22full%22%7D
By default, owner and ACL are not fetched by get_blob. You will have to explicitly fetch this info:
blob = client(project='project').get_bucket('bucket').get_blob('blob')
blob.reload(projection='full')
Note that if you use uniform bucket-level ACLs owner doesn't have any meaning and will be unset even with the above change.
EDIT: this is actually not the most efficient option because it makes an extra unnecessary call to GCS. The most efficient option is:
blob = Blob('bucket', 'blob')
blob.reload(projection='full', client=client)

How to check whether a user exists when setting IAM policy in google Big-query?

I'm trying to set IAM policy in google Bigquery using Python. I'm doing it in the following way:
Get the current policy
Create a list of new members e.g. ['someone#gmail.com', 'someother#gmail.com', ...]
Modify the policy by adding the members from the above-created list
Set policy by calling setIamPolicy method.
The problem with the above approach is that it throws an error HttpError 400 User ... doesn't exist when anyone from the members list doesn't exist.
How can I avoid this issue? Is there any API to check whether a user exists or not?
I can also do it using a loop so that if one setIamPolicy call fails(because of user doesn't exits), other memberes still get added but that ends up calling the API multiple times.
If you have a mapping from emails to users, you can add the following simple python code using boto3 to check if the user exists in aws or not.
import boto3
iam = boto3.resource('iam')
user = iam.User('name')
user.load()
This will throw a NoSuchEntityException exception if the user doesn't exist.
You can catch the exception and continue if the user doesn't exist. If successful loaded you'll be able to access the users attributes, e.g. user.arn.

How to set the VATLAYER_ACCESS_KEY in Saleor eCommerce Platform?

Saleor Django eCommerce Platform. I have just started setting up and learning Saleor and I am stuck setting the VATLAYER_ACCESS_KEY. I get the following error (Could not fetch tax rates. Make sure you have supplied a valid API Access Key. Check the server logs for more information about this error.). I have registered for a key API at VatLayer https://vatlayer.com/
I have set the key "this key is an example" in the common.env file as VATLAYER_ACCESS_KEY=2bb221d7fbce9fd274791959e120999d.
Is this the correct location to set the key or should it be in the saleor/settings.py file and are there additional settings I need to apply to enable VatLayer?
To successfully fetch tax rates for Saleor eCommerce Platform using your own VATLAYER_API_KEY supplied by https://vatlayer.com/.
Edit the saleor/settings.py file, search for VATLAYER_ACCESS_KEY, and change:
VATLAYER_ACCESS_KEY = os.environ.get("VATLAYER_ACCESS_KEY")
to:
VATLAYER_ACCESS_KEY = os.environ.get("VATLAYER_ACCESS_KEY", "add_my_vat_layer_access_key_here")
and save.

How do I get IAM user owner for any particular AWS resource using Boto & Python?

I'm trying to get the User Owner of any particular AWS resource, be it instance, volume, security group etc..
I searched but could not find any helpful information apart from this
Link,
This is what I found closer [The answer suggests we can get the user who created an instance] to what I'm looking for but still couldn't use it as the code mentioned is not complete.
If I consider the code from above mentioned post's answer, the following line
ct_conn = sess.client(service_name='cloudtrail',region_name='us-east-1')
is mentioned without defining the "sess".
AWS will not records any AWS user activities info unless you setup Cloudtrail and send those info to S3 repository.

Categories