azure-devops-python-samples
azure-devops-python-samples copied to clipboard
Functionality to add a user to azure devops from AAD
Is it possible to use azure.devops.v5_0.graph module? Can't find any sample that supports the functionality to create a new user from AAD to azure devops.
Do we have something like this in python? : https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/Graph/UsersSample.cs
I am able to list the users. But cannot create a new user as 'GraphUserPrincipalNameContext' class is not available in the API.
https://github.com/microsoft/azure-devops-python-api/blob/dev/azure-devops/azure/devops/v5_0/graph/graph_client.py ?
https://github.com/microsoft/azure-devops-python-api/blob/dev/azure-devops/azure/devops/v5_0/graph/graph_client.py ?
I already referred to it. We can use the create_user function from that client. But the function asks for a <azure.devops.v5_0.graph.models.GraphUserCreationContext> object as input parameter.
But the microsoft documentation ( https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/users/create?view=azure-devops-rest-5.0 ) says that "The body of the request must be a derived type of GraphUserCreationContext such as GraphUserMailAddressCreationContext, GraphUserOriginIdCreationContext , or GraphUserPrincipalNameCreationContext."
So i decided to use GraphUserPrincipalNameCreationContext. But such a class/interface is not available in python. I am confused that how should I use the create_user method. That's why I asked for a sample.
Ah, sorry, thanks for the correction. @tedchamb @ramrajesh it looks like nothing in the Python API derives from GraphUserCreationContext
. I don't know if this is a client gen problem or a graph API problem. Can one of you help?
This is a duplicate to this issue: https://github.com/microsoft/azure-devops-python-api/issues/176
The generator does not know about the sub types, so does not generate them. We need to fix that. In the meantime you should be able to create your own sub types for these.
This is a duplicate to this issue: microsoft/azure-devops-python-api#176
The generator does not know about the sub types, so does not generate them. We need to fix that. In the meantime you should be able to create your own sub types for these.
Do you mean that I should define a GraphUserPrincipalNameCreationContext
class as a subclass of GraphUserCreationContext
in my script itself as of now?
Yes.
@AnjanaAK I added this to my project:
class GraphUserPrincipalNameCreationContext(GraphUserCreationContext):
_attribute_map = {
'storage_key': {'key': 'storageKey', 'type': 'str'},
'principal_name': {'key': 'principalName', 'type': 'str'}
}
def __init__(self, storage_key=None, principal_name=None):
super(GraphUserPrincipalNameCreationContext, self).__init__()
self.principal_name = principal_name
@tedchamb do you have any indication when the generator is fixed or point me to where I could help to add this sub-classes to the generator
@tedchamb Any updates on this, we are also impacted by this bug.
@KaiWalter @vtbassmatt @tedchamb Could you please help me how to configure this missing class properly, I added it to my script and then used it like that:
client = self.__get_connection().clients_v6_0.get_graph_client()
creation_context = GraphUserPrincipalNameCreationContext(
principal_name="GROUP_NAME"
)
try:
group = client.create_group(
creation_context=creation_context,
scope_descriptor="DEV"
)
but still getting the same error:
VS860014: Must have exactly one of originId, principalName or displayName set
@mo-saeed can you please check my script https://github.com/KaiWalter/azure-devops-principalName-migration/blob/b5cdae45f47bcdcfb9c70e3c4e0d7fd2d59eb89e/modules/rebuild.py#L150 - I do it with an own definition of GraphUserOriginIdCreationContext
https://github.com/KaiWalter/azure-devops-principalName-migration/blob/b5cdae45f47bcdcfb9c70e3c4e0d7fd2d59eb89e/modules/rebuild.py#L196
maybe this helps