Repository: Azure/azure-cli-extensions

Issue:
Identity is empty after creating Azure Datafactory with Azure DevOps pipeline
- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)

### Extension name (the extension in question)
datafactory                        0.2.0

### Description of issue (in as much detail as possible)
When creating a Azure datafactory using CLI and a service connection in Azure DevOps, the identity fields is $null

<img width="1239" alt="2020-11-03 16_21_51-Microsoft Store" src="https://user-images.githubusercontent.com/18550104/98005087-fb46a680-1df0-11eb-8939-98e670c584df.png">
<img width="653" alt="2020-11-03 16_17_15-Pipelines - Run 20201103 2 logs" src="https://user-images.githubusercontent.com/18550104/98005091-fbdf3d00-1df0-11eb-9902-54b9e3c78e3a.png">

-----




Discussion:
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @shawnxzq, @lmy269.
datafactory 
hi @fengzhou-msft could you pls help here?
@fengzhou-msft Any ideas on this? Is there any difference between CLI command and PS command? 
@tonswart Please use PS command to work around the issue for now, thanks! 
@tonswart we are still working on this, and please keep using the PS command as a workaround, thanks.
@fengzhou-msft Looks like the "identity" property is defined in swagger, but and it's included in the PS command but missed in CLI, could you please take care of this? Thanks!
The datafactory extension is auto-generated for breadth coverage and the behavior is a bit strange for identity. The `factory create` command will create a factory [with no identity](https://github.com/Azure/azure-cli-extensions/blob/49441906deab33f894e0020aac7258ab55812f73/src/datafactory/azext_datafactory/generated/custom.py#L57), but if you call `datafactory update` command, it's supposed to [add system assigned identity](https://github.com/Azure/azure-cli-extensions/blob/49441906deab33f894e0020aac7258ab55812f73/src/datafactory/azext_datafactory/generated/custom.py#L69). But it's currently not working, it may be an issue on the patch update method of the service, @shawnxzq.

To reproduce, run `az datafactory factory create...` and then `az datafcatory factory update... --tags env=test --debug`, you will see the request body is `{"tags": {"env": "test"}, "identity": {"type": "SystemAssigned"}}` in debug message, but the response shows tag is updated but identity is still null.

@tonswart We're working with Managed Identity team on revising the common CLI pattern for identity operations, we will support the datafactory create command with managed identity after we have a final design. As a workaround for now, you can use the following command to create a datafactory with system assigned identity:
`az rest --method put 
--uri "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}?api-version=2018-06-01" 
--body "{\"location\":\"westus2\",\"identity\":{\"type\":\"SystemAssigned\"}}" --headers Content-Type=application/json `
Replace the `factoryName` in the uri with your own values. If you would like to add more parameters in body, you can run `az datafactory factory create` command with the options you need and `--debug` in the end. Then check the request body in debug message and copy the parameters to the `az rest` command.



Resolving patch:
diff --git a/src/datafactory/azext_datafactory/manual/custom.py b/src/datafactory/azext_datafactory/manual/custom.py
new file mode 100644
--- /dev/null
+++ b/src/datafactory/azext_datafactory/manual/custom.py
@@ -0,0 +1,40 @@
+# --------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License.txt in the project root for
+# license information.
+#
+# Code generated by Microsoft (R) AutoRest Code Generator.
+# Changes may cause incorrect behavior and will be lost if the code is
+# regenerated.
+# --------------------------------------------------------------------------
+
+from knack.util import CLIError
+
+
+def datafactory_factory_create(client,
+                               resource_group_name,
+                               factory_name,
+                               if_match=None,
+                               location=None,
+                               tags=None,
+                               factory_vsts_configuration=None,
+                               factory_git_hub_configuration=None,
+                               global_parameters=None):
+    from azext_datafactory.vendored_sdks.datafactory.models import FactoryIdentity
+    all_repo_configuration = []
+    if factory_vsts_configuration is not None:
+        all_repo_configuration.append(factory_vsts_configuration)
+    if factory_git_hub_configuration is not None:
+        all_repo_configuration.append(factory_git_hub_configuration)
+    if len(all_repo_configuration) > 1:
+        raise CLIError('At most one of --factory-vsts-configuration, --factory-git-hub-configuration is needed for '
+                       'repo configuration!')
+    repo_configuration = all_repo_configuration[0] if len(all_repo_configuration) == 1 else None
+    return client.create_or_update(resource_group_name=resource_group_name,
+                                   factory_name=factory_name,
+                                   if_match=if_match,
+                                   location=location,
+                                   tags=tags,
+                                   identity=FactoryIdentity(),
+                                   repo_configuration=repo_configuration,
+                                   global_parameters=global_parameters)
diff --git a/src/datafactory/azext_datafactory/manual/version.py b/src/datafactory/azext_datafactory/manual/version.py
--- a/src/datafactory/azext_datafactory/manual/version.py
+++ b/src/datafactory/azext_datafactory/manual/version.py
@@ -8,4 +8,4 @@
 # regenerated.
 # --------------------------------------------------------------------------
 
-VERSION = "0.2.0"
+VERSION = "0.2.1"


Test patch: