|
| 1 | +# Code snippets and samples |
| 2 | + |
| 3 | + |
| 4 | +## Operations |
| 5 | + |
| 6 | +- [List](#operations_list) |
| 7 | + |
| 8 | +## SystemAssignedIdentities |
| 9 | + |
| 10 | +- [GetByScope](#systemassignedidentities_getbyscope) |
| 11 | + |
| 12 | +## UserAssignedIdentities |
| 13 | + |
| 14 | +- [CreateOrUpdate](#userassignedidentities_createorupdate) |
| 15 | +- [Delete](#userassignedidentities_delete) |
| 16 | +- [GetByResourceGroup](#userassignedidentities_getbyresourcegroup) |
| 17 | +- [List](#userassignedidentities_list) |
| 18 | +- [ListAssociatedResources](#userassignedidentities_listassociatedresources) |
| 19 | +- [ListByResourceGroup](#userassignedidentities_listbyresourcegroup) |
| 20 | +- [Update](#userassignedidentities_update) |
| 21 | +### Operations_List |
| 22 | + |
| 23 | +```java |
| 24 | +import com.azure.core.util.Context; |
| 25 | + |
| 26 | +/** Samples for Operations List. */ |
| 27 | +public final class OperationsListSamples { |
| 28 | + /* |
| 29 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/MsiOperationsList.json |
| 30 | + */ |
| 31 | + /** |
| 32 | + * Sample code: MsiOperationsList. |
| 33 | + * |
| 34 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 35 | + */ |
| 36 | + public static void msiOperationsList( |
| 37 | + com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 38 | + manager.operations().list(Context.NONE); |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +### SystemAssignedIdentities_GetByScope |
| 44 | + |
| 45 | +```java |
| 46 | +import com.azure.core.util.Context; |
| 47 | + |
| 48 | +/** Samples for SystemAssignedIdentities GetByScope. */ |
| 49 | +public final class SystemAssignedIdentitiesGetByScopeSamples { |
| 50 | + /* |
| 51 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/SystemAssignedIdentityGet.json |
| 52 | + */ |
| 53 | + /** |
| 54 | + * Sample code: MsiOperationsList. |
| 55 | + * |
| 56 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 57 | + */ |
| 58 | + public static void msiOperationsList( |
| 59 | + com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 60 | + manager.systemAssignedIdentities().getByScopeWithResponse("scope", Context.NONE); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### UserAssignedIdentities_CreateOrUpdate |
| 66 | + |
| 67 | +```java |
| 68 | +import java.util.HashMap; |
| 69 | +import java.util.Map; |
| 70 | + |
| 71 | +/** Samples for UserAssignedIdentities CreateOrUpdate. */ |
| 72 | +public final class UserAssignedIdentitiesCreateOrUpdateSamples { |
| 73 | + /* |
| 74 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityCreate.json |
| 75 | + */ |
| 76 | + /** |
| 77 | + * Sample code: IdentityCreate. |
| 78 | + * |
| 79 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 80 | + */ |
| 81 | + public static void identityCreate(com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 82 | + manager |
| 83 | + .userAssignedIdentities() |
| 84 | + .define("resourceName") |
| 85 | + .withRegion("eastus") |
| 86 | + .withExistingResourceGroup("rgName") |
| 87 | + .withTags(mapOf("key1", "value1", "key2", "value2")) |
| 88 | + .create(); |
| 89 | + } |
| 90 | + |
| 91 | + @SuppressWarnings("unchecked") |
| 92 | + private static <T> Map<String, T> mapOf(Object... inputs) { |
| 93 | + Map<String, T> map = new HashMap<>(); |
| 94 | + for (int i = 0; i < inputs.length; i += 2) { |
| 95 | + String key = (String) inputs[i]; |
| 96 | + T value = (T) inputs[i + 1]; |
| 97 | + map.put(key, value); |
| 98 | + } |
| 99 | + return map; |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### UserAssignedIdentities_Delete |
| 105 | + |
| 106 | +```java |
| 107 | +import com.azure.core.util.Context; |
| 108 | + |
| 109 | +/** Samples for UserAssignedIdentities Delete. */ |
| 110 | +public final class UserAssignedIdentitiesDeleteSamples { |
| 111 | + /* |
| 112 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityDelete.json |
| 113 | + */ |
| 114 | + /** |
| 115 | + * Sample code: IdentityDelete. |
| 116 | + * |
| 117 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 118 | + */ |
| 119 | + public static void identityDelete(com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 120 | + manager.userAssignedIdentities().deleteWithResponse("rgName", "resourceName", Context.NONE); |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +### UserAssignedIdentities_GetByResourceGroup |
| 126 | + |
| 127 | +```java |
| 128 | +import com.azure.core.util.Context; |
| 129 | + |
| 130 | +/** Samples for UserAssignedIdentities GetByResourceGroup. */ |
| 131 | +public final class UserAssignedIdentitiesGetByResourceGroupSamples { |
| 132 | + /* |
| 133 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityGet.json |
| 134 | + */ |
| 135 | + /** |
| 136 | + * Sample code: IdentityGet. |
| 137 | + * |
| 138 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 139 | + */ |
| 140 | + public static void identityGet(com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 141 | + manager.userAssignedIdentities().getByResourceGroupWithResponse("rgName", "resourceName", Context.NONE); |
| 142 | + } |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +### UserAssignedIdentities_List |
| 147 | + |
| 148 | +```java |
| 149 | +import com.azure.core.util.Context; |
| 150 | + |
| 151 | +/** Samples for UserAssignedIdentities List. */ |
| 152 | +public final class UserAssignedIdentitiesListSamples { |
| 153 | + /* |
| 154 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityListBySubscription.json |
| 155 | + */ |
| 156 | + /** |
| 157 | + * Sample code: IdentityListBySubscription. |
| 158 | + * |
| 159 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 160 | + */ |
| 161 | + public static void identityListBySubscription( |
| 162 | + com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 163 | + manager.userAssignedIdentities().list(Context.NONE); |
| 164 | + } |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +### UserAssignedIdentities_ListAssociatedResources |
| 169 | + |
| 170 | +```java |
| 171 | +import com.azure.core.util.Context; |
| 172 | + |
| 173 | +/** Samples for UserAssignedIdentities ListAssociatedResources. */ |
| 174 | +public final class UserAssignedIdentitiesListAssociatedResourcesSamples { |
| 175 | + /* |
| 176 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityListAssociatedResources.json |
| 177 | + */ |
| 178 | + /** |
| 179 | + * Sample code: IdentityListAssociatedResources. |
| 180 | + * |
| 181 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 182 | + */ |
| 183 | + public static void identityListAssociatedResources( |
| 184 | + com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 185 | + manager |
| 186 | + .userAssignedIdentities() |
| 187 | + .listAssociatedResources( |
| 188 | + "testrg", "testid", "contains(name, 'test')", "name asc", 10, 1, null, Context.NONE); |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +### UserAssignedIdentities_ListByResourceGroup |
| 194 | + |
| 195 | +```java |
| 196 | +import com.azure.core.util.Context; |
| 197 | + |
| 198 | +/** Samples for UserAssignedIdentities ListByResourceGroup. */ |
| 199 | +public final class UserAssignedIdentitiesListByResourceGroupSamples { |
| 200 | + /* |
| 201 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityListByResourceGroup.json |
| 202 | + */ |
| 203 | + /** |
| 204 | + * Sample code: IdentityListByResourceGroup. |
| 205 | + * |
| 206 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 207 | + */ |
| 208 | + public static void identityListByResourceGroup( |
| 209 | + com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 210 | + manager.userAssignedIdentities().listByResourceGroup("rgName", Context.NONE); |
| 211 | + } |
| 212 | +} |
| 213 | +``` |
| 214 | + |
| 215 | +### UserAssignedIdentities_Update |
| 216 | + |
| 217 | +```java |
| 218 | +import com.azure.core.util.Context; |
| 219 | +import com.azure.resourcemanager.msi.generated.models.Identity; |
| 220 | +import java.util.HashMap; |
| 221 | +import java.util.Map; |
| 222 | + |
| 223 | +/** Samples for UserAssignedIdentities Update. */ |
| 224 | +public final class UserAssignedIdentitiesUpdateSamples { |
| 225 | + /* |
| 226 | + * x-ms-original-file: specification/msi/resource-manager/Microsoft.ManagedIdentity/preview/2021-09-30-preview/examples/IdentityUpdate.json |
| 227 | + */ |
| 228 | + /** |
| 229 | + * Sample code: IdentityUpdate. |
| 230 | + * |
| 231 | + * @param manager Entry point to ManagedServiceIdentityManager. |
| 232 | + */ |
| 233 | + public static void identityUpdate(com.azure.resourcemanager.msi.generated.ManagedServiceIdentityManager manager) { |
| 234 | + Identity resource = |
| 235 | + manager |
| 236 | + .userAssignedIdentities() |
| 237 | + .getByResourceGroupWithResponse("rgName", "resourceName", Context.NONE) |
| 238 | + .getValue(); |
| 239 | + resource.update().withTags(mapOf("key1", "value1", "key2", "value2")).apply(); |
| 240 | + } |
| 241 | + |
| 242 | + @SuppressWarnings("unchecked") |
| 243 | + private static <T> Map<String, T> mapOf(Object... inputs) { |
| 244 | + Map<String, T> map = new HashMap<>(); |
| 245 | + for (int i = 0; i < inputs.length; i += 2) { |
| 246 | + String key = (String) inputs[i]; |
| 247 | + T value = (T) inputs[i + 1]; |
| 248 | + map.put(key, value); |
| 249 | + } |
| 250 | + return map; |
| 251 | + } |
| 252 | +} |
| 253 | +``` |
| 254 | + |
0 commit comments