michelmetran opened a new issue, #91:
URL: https://github.com/apache/airflow-client-python/issues/91

   I'm trying to create users using "airflow-client-python".
   I can create users without defining roles. Automatically the user will be 
"Public".
   
   ```python
   # Imports
   from airflow_client import client
   from airflow_client.client.api import user_api
   from pprint import pprint
   from airflow_client.client.model.user import User
   from airflow_client.client.model.user_collection_item_roles import 
UserCollectionItemRoles
   
   # Configure
   configuration = client.Configuration(
       host='http://localhost:8080/api/v1',
       username='airflow',
       password='airflow',
   )
   
   # Set User
   user = User(
       first_name='Michel',
       last_name='Metran',
       username='mmetran',
       email='[email protected]',
       password='1111',
   )
   
   # Enter a context with an instance of the API client
   with client.ApiClient(configuration) as api:
       # Create an instance of the API class
       api_instance = user_api.UserApi(api)
       try:
           # Create a user
           api_response = api_instance.post_user(user)
           pprint(api_response)
           
       except client.ApiException as e:
           print(f'Exception when calling UserApi:\n{e}')
   ```
   <br>
   
   The output will be...
   
   ```shell
   {'active': True,
    'changed_on': '2023-08-03T23:17:12.002701',
    'created_on': '2023-08-03T23:17:12.002684',
    'email': '[email protected]',
    'fail_login_count': None,
    'first_name': 'Michel',
    'last_login': None,
    'last_name': 'Metran',
    'login_count': None,
    'roles': [{'name': 'Public'}],
    'username': 'mmetran'}
   ```
   
   <br>
   
   So, I tried the same "type" of the output: *list* to define another role... 
   ... *list* not work...
   
   How to create a user with another definition for role!?
   I've tried several things and nothing works.
   
   ```shell
   user = User(
       first_name='Michel',
       last_name='Metran',
       username='mmetran',
       email='[email protected]',
       password='1111',
       roles=([{'name': 'Public'}]),    # Error=Invalid type for variable '0'. 
Required value type is UserCollectionItemRoles and passed type was dict at 
['roles'][0]
       #roles='Admin' # Error=Invalid type for variable 'roles'. Required value 
type is list and passed type was str at ['roles']
       #roles=['Public'], # Error=Invalid type for variable '0'. Required value 
type is UserCollectionItemRoles and passed type was str at ['roles'][0]
       #roles=UserCollectionItemRoles(), # Error=Invalid type for variable 
'roles'. Required value type is list and passed type was 
UserCollectionItemRoles at ['roles']
   )
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to