This project is a web application for managing Classroom instruction and operations. It is built using Flask, SQLAlchemy, and other requirements.txt dependencies.
Creating a user in Kasm involves a series of steps. First, the system checks if the required environment variables are set. These variables include the Kasm server address and the API keys. If these are not set, the process is halted and an error message is returned.
Once the environment variables are confirmed, the system validates the credentials by sending a POST request to the Kasm server. If the credentials are invalid, an error message is returned.
After successful validation, the system proceeds to create the user. The user's full name is split into first and last names. If the user's name consists of a single word, it is taken as the first name and the last name is left blank.
The system then checks if a password is provided. If not, an error message is returned. If a password is provided, a POST request is sent to the Kasm server to create the user. The request includes the user's details such as username, first and last names, and password.
Deleting a Kasm User
Deleting a user in Kasm also involves a series of steps. Similar to creating a user, the system first checks if the required environment variables are set and validates the credentials.
Once the credentials are validated, the system retrieves a list of all users from the Kasm server. It then searches for the user to be deleted in this list. If the user is not found, an error message is returned.
If the user is found, the system sends a POST request to the Kasm server to delete the user. The request includes the user's ID. If the deletion is successful, the system returns a success message.
Implementation
To implement the Kasm delete function, you must follow this structure of code and implement it as a POST method, if you request documentation, see here
def post(self):
body = request.get_json()
user = body.get('user')
if user is None:
return {'message': f'User ID is missing'}, 400
else:
KasmDeleteUser().post(user)
return {'message': f'User {user} deleted from Kasm'}, 200
All thats needed is a user check for if the user id is provided then it goes to Kasm and deletes the user, Kasm has its own checks for if the user does not exist so thats not included here.
For how to create users, it is also a POST request following this structure
kasm_server_needed = body.get('kasm_server_needed')
if kasm_server_needed:
KasmCreateUser().post(uid, name, password)
Creating a Kasm User
Creating a user in Kasm involves a series of steps. First, the system checks if the required environment variables are set. These variables include the Kasm server address and the API keys. If these are not set, the process is halted and an error message is returned.
Once the environment variables are confirmed, the system validates the credentials by sending a POST request to the Kasm server. If the credentials are invalid, an error message is returned.
After successful validation, the system proceeds to create the user. The user's full name is split into first and last names. If the user's name consists of a single word, it is taken as the first name and the last name is left blank.
The system then checks if a password is provided. If not, an error message is returned. If a password is provided, a POST request is sent to the Kasm server to create the user. The request includes the user's details such as username, first and last names, and password.
Deleting a Kasm User
Deleting a user in Kasm also involves a series of steps. Similar to creating a user, the system first checks if the required environment variables are set and validates the credentials.
Once the credentials are validated, the system retrieves a list of all users from the Kasm server. It then searches for the user to be deleted in this list. If the user is not found, an error message is returned.
If the user is found, the system sends a POST request to the Kasm server to delete the user. The request includes the user's ID. If the deletion is successful, the system returns a success message.
Implementation
To implement the Kasm delete function, you must follow this structure of code and implement it as a POST method, if you request documentation, see here
All thats needed is a user check for if the user id is provided then it goes to Kasm and deletes the user, Kasm has its own checks for if the user does not exist so thats not included here. For how to create users, it is also a POST request following this structure