You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "michelmetran (via GitHub)" <gi...@apache.org> on 2023/08/03 23:28:39 UTC

[GitHub] [airflow-client-python] michelmetran opened a new issue, #91: How Create Users with role Admin?

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='mmetran@gmail.com',
       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': 'mmetran@gmail.com',
    '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='mmetran@gmail.com',
       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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] pierrejeambrun commented on issue #91: How Create Users with role Admin?

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on issue #91:
URL: https://github.com/apache/airflow-client-python/issues/91#issuecomment-1665923979

   Hello,
   
   What version of the client are you on, and what is the version of airflow running ?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] pierrejeambrun closed issue #91: How Create Users with role Admin?

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun closed issue #91: How Create Users with role Admin?
URL: https://github.com/apache/airflow-client-python/issues/91


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] michelmetran commented on issue #91: How Create Users with role Admin?

Posted by "michelmetran (via GitHub)" <gi...@apache.org>.
michelmetran commented on issue #91:
URL: https://github.com/apache/airflow-client-python/issues/91#issuecomment-1665941367

   Hi @pierrejeambrun !
   Thanks for the help!
   
   I'm using the latest version of both: airflow and airflow-client.
   However, in airflow the latest version is 2.6.3
   While at the airflow-client we are at 2.6.2
   
   I'm using AirFlow through docker-compose...
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] pierrejeambrun commented on issue #91: How Create Users with role Admin?

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on issue #91:
URL: https://github.com/apache/airflow-client-python/issues/91#issuecomment-1666506609

   Hello @michelmetran,
   
   You can achieve that like this:
   ```python
       user = User(
           first_name='Michel',
           last_name='Metran',
           username='mmetran',
           email='mmetran@gmail.com',
           password='1111',
           roles=[UserCollectionItemRoles(name="Admin")]
       )
   ``` 
   
   Marking as closed. Feel free to re-open if needed.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] michelmetran commented on issue #91: How Create Users with role Admin?

Posted by "michelmetran (via GitHub)" <gi...@apache.org>.
michelmetran commented on issue #91:
URL: https://github.com/apache/airflow-client-python/issues/91#issuecomment-1666549881

   Thanks for the help @pierrejeambrun !!


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow-client-python] pierrejeambrun commented on issue #91: How Create Users with role Admin?

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on issue #91:
URL: https://github.com/apache/airflow-client-python/issues/91#issuecomment-1665927186

   I am not at home right know but will try on latest this week end.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org