JongPil
JongPil

Reputation: 11

How can I have multiple Azure user info on a single server?

I'm developing an API that calls subscription and tenant information when a user logs in to azure through azure-cli.

When a user logs in to CSP(internally, CSP login is performed using az login --use-device-code), the user receives the url https://microsoft.com/devicelogin and a secret code.

After completing this process, the user's login information is left on our main server, and the user's subscription and tenant information can be called using this.

In the case of a single user, this process has no problem at all. But, when multiple users make a request at the same time, the information of only the user who made the last request is called.

In addition, another problem is that the main server's process is blocked until the process is finished when requested via azure-cli.

When multiple users request CSP login, what is the way to operate normally without blocking the main server and without overwriting user information?

For reference, the main server is FastAPI.

Upvotes: 0

Views: 154

Answers (1)

Navaneeth Sen
Navaneeth Sen

Reputation: 6466

Based on what you have explained, it looks like you have a fast api server which exposes an api which the users use for login. The response from the api will be the device-login url and the device code for the client to use. All the subsequent calls will be done using this information.

So now the first problem is the main thread issue, where the api should not get block until the process is done.

For this you need to have asynchronous apis, which performs background jobs and inform the user when the task is complete or the user can request for the information periodically until the job status changes.

This means we will need to modify our fastapi server with something that can perform multi-threading, queue tasks and have some lookup cache.

The best approach I suggest is having a fastapi stack with the below libs:

  • Celery - an asynchronous task manager that lets you run and manage jobs in a queue.
  • RabbitMQ - a message broker that is used to communicate between the task workers and Celery
  • Redis - an in-memory cache (key-value store) for storing and retrieving values.

You can use the same Redis cache to solve your second problem asw well where you need to store and use multiple session information without overwriting. This will help you handle multiple session info or multiple user infor.

Please have a look at some sample projects from github below:

jjpizarro/fastapi-celery-1

CloudNua/fastapi-celery

Upvotes: 0

Related Questions