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