From 0a2fc47d4d734a9f51e2eb99cf5309dca21246e7 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Mon, 27 Jan 2025 13:39:15 +0000 Subject: [PATCH] Updating based on 6dbdfa5d4 --- .../dashboard/2024-10-01/client.go | 73 ++ .../2024-10-01/grafanaplugin/README.md | 37 + .../2024-10-01/grafanaplugin/client.go | 26 + .../2024-10-01/grafanaplugin/id_grafana.go | 130 +++ .../grafanaplugin/id_grafana_test.go | 282 ++++++ .../method_grafanafetchavailableplugins.go | 105 +++ .../model_grafanaavailableplugin.go | 9 + .../2024-10-01/grafanaplugin/predicates.go | 22 + .../2024-10-01/grafanaplugin/version.go | 10 + .../2024-10-01/grafanaresource/README.md | 137 +++ .../2024-10-01/grafanaresource/client.go | 26 + .../2024-10-01/grafanaresource/constants.go | 491 ++++++++++ .../2024-10-01/grafanaresource/id_grafana.go | 130 +++ .../grafanaresource/id_grafana_test.go | 282 ++++++ .../method_grafanacheckenterprisedetails.go | 54 ++ .../grafanaresource/method_grafanacreate.go | 75 ++ .../grafanaresource/method_grafanadelete.go | 71 ++ .../grafanaresource/method_grafanaget.go | 53 ++ .../grafanaresource/method_grafanalist.go | 106 +++ .../method_grafanalistbyresourcegroup.go | 106 +++ .../grafanaresource/method_grafanaupdate.go | 58 ++ .../model_azuremonitorworkspaceintegration.go | 8 + .../model_enterpriseconfigurations.go | 9 + .../model_enterprisedetails.go | 9 + .../model_grafanaconfigurations.go | 11 + .../model_grafanaintegrations.go | 8 + .../grafanaresource/model_grafanaplugin.go | 8 + .../grafanaresource/model_managedgrafana.go | 21 + .../model_managedgrafanaproperties.go | 22 + ...anagedgrafanapropertiesupdateparameters.go | 16 + .../model_managedgrafanaupdateparameters.go | 15 + .../model_marketplacetrialquota.go | 41 + .../grafanaresource/model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 16 + ...del_privateendpointconnectionproperties.go | 11 + ...model_privatelinkserviceconnectionstate.go | 10 + .../grafanaresource/model_resourcesku.go | 8 + .../model_saassubscriptiondetails.go | 11 + .../grafanaresource/model_security.go | 8 + .../2024-10-01/grafanaresource/model_smtp.go | 15 + .../grafanaresource/model_snapshots.go | 8 + .../grafanaresource/model_subscriptionterm.go | 40 + .../2024-10-01/grafanaresource/model_users.go | 8 + .../2024-10-01/grafanaresource/predicates.go | 32 + .../2024-10-01/grafanaresource/version.go | 10 + .../2024-10-01/integrationfabric/README.md | 99 ++ .../2024-10-01/integrationfabric/client.go | 26 + .../2024-10-01/integrationfabric/constants.go | 72 ++ .../integrationfabric/id_grafana.go | 130 +++ .../integrationfabric/id_grafana_test.go | 282 ++++++ .../integrationfabric/id_integrationfabric.go | 139 +++ .../id_integrationfabric_test.go | 327 +++++++ .../integrationfabric/method_create.go | 75 ++ .../integrationfabric/method_delete.go | 70 ++ .../integrationfabric/method_get.go | 53 ++ .../integrationfabric/method_list.go | 105 +++ .../integrationfabric/method_update.go | 75 ++ .../model_integrationfabric.go | 18 + .../model_integrationfabricproperties.go | 11 + ...grationfabricpropertiesupdateparameters.go | 8 + ...model_integrationfabricupdateparameters.go | 9 + .../integrationfabric/predicates.go | 32 + .../2024-10-01/integrationfabric/version.go | 10 + .../managedprivateendpoints/README.md | 111 +++ .../managedprivateendpoints/client.go | 26 + .../managedprivateendpoints/constants.go | 119 +++ .../managedprivateendpoints/id_grafana.go | 130 +++ .../id_grafana_test.go | 282 ++++++ .../id_managedprivateendpoint.go | 139 +++ .../id_managedprivateendpoint_test.go | 327 +++++++ .../managedprivateendpoints/method_create.go | 75 ++ .../managedprivateendpoints/method_delete.go | 71 ++ .../managedprivateendpoints/method_get.go | 53 ++ .../managedprivateendpoints/method_list.go | 105 +++ .../managedprivateendpoints/method_refresh.go | 70 ++ .../managedprivateendpoints/method_update.go | 75 ++ ...l_managedprivateendpointconnectionstate.go | 9 + .../model_managedprivateendpointmodel.go | 18 + ...l_managedprivateendpointmodelproperties.go | 15 + ..._managedprivateendpointupdateparameters.go | 8 + .../managedprivateendpoints/predicates.go | 32 + .../managedprivateendpoints/version.go | 10 + .../privateendpointconnection/README.md | 82 ++ .../privateendpointconnection/client.go | 26 + .../privateendpointconnection/constants.go | 101 ++ .../privateendpointconnection/id_grafana.go | 130 +++ .../id_grafana_test.go | 282 ++++++ .../id_privateendpointconnection.go | 139 +++ .../id_privateendpointconnection_test.go | 327 +++++++ .../method_approve.go | 74 ++ .../method_delete.go | 70 ++ .../privateendpointconnection/method_get.go | 53 ++ .../privateendpointconnection/method_list.go | 105 +++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 16 + ...del_privateendpointconnectionproperties.go | 11 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnection/predicates.go | 27 + .../privateendpointconnection/version.go | 10 + .../2024-10-01/privatelinkresource/README.md | 53 ++ .../2024-10-01/privatelinkresource/client.go | 26 + .../privatelinkresource/constants.go | 72 ++ .../privatelinkresource/id_grafana.go | 130 +++ .../privatelinkresource/id_grafana_test.go | 282 ++++++ .../id_privatelinkresource.go | 139 +++ .../id_privatelinkresource_test.go | 327 +++++++ .../privatelinkresource/method_get.go | 53 ++ .../privatelinkresource/method_list.go | 105 +++ .../model_privatelinkresource.go | 16 + .../model_privatelinkresourceproperties.go | 11 + .../privatelinkresource/predicates.go | 27 + .../2024-10-01/privatelinkresource/version.go | 10 + .../keyvault/2024-11-01/client.go | 118 +++ .../keyvault/2024-11-01/keys/README.md | 108 +++ .../keyvault/2024-11-01/keys/client.go | 26 + .../keyvault/2024-11-01/keys/constants.go | 251 +++++ .../keys/method_createifnotexist.go | 58 ++ .../keyvault/2024-11-01/keys/method_get.go | 54 ++ .../2024-11-01/keys/method_getversion.go | 54 ++ .../keyvault/2024-11-01/keys/method_list.go | 106 +++ .../2024-11-01/keys/method_listversions.go | 106 +++ .../keyvault/2024-11-01/keys/model_action.go | 8 + .../keyvault/2024-11-01/keys/model_key.go | 13 + .../2024-11-01/keys/model_keyattributes.go | 14 + .../keys/model_keycreateparameters.go | 9 + .../2024-11-01/keys/model_keyproperties.go | 16 + .../2024-11-01/keys/model_keyreleasepolicy.go | 9 + .../keys/model_keyrotationpolicyattributes.go | 10 + .../2024-11-01/keys/model_lifetimeaction.go | 9 + .../2024-11-01/keys/model_rotationpolicy.go | 9 + .../keyvault/2024-11-01/keys/model_trigger.go | 9 + .../keyvault/2024-11-01/keys/predicates.go | 32 + .../keyvault/2024-11-01/keys/version.go | 10 + .../2024-11-01/managedhsmkeys/README.md | 107 +++ .../2024-11-01/managedhsmkeys/client.go | 26 + .../2024-11-01/managedhsmkeys/constants.go | 251 +++++ .../2024-11-01/managedhsmkeys/id_key.go | 139 +++ .../2024-11-01/managedhsmkeys/id_key_test.go | 327 +++++++ .../managedhsmkeys/id_managedhsm.go | 130 +++ .../managedhsmkeys/id_managedhsm_test.go | 282 ++++++ .../2024-11-01/managedhsmkeys/id_version.go | 148 +++ .../managedhsmkeys/id_version_test.go | 372 ++++++++ .../managedhsmkeys/method_createifnotexist.go | 57 ++ .../2024-11-01/managedhsmkeys/method_get.go | 53 ++ .../managedhsmkeys/method_getversion.go | 53 ++ .../2024-11-01/managedhsmkeys/method_list.go | 105 +++ .../managedhsmkeys/method_listversions.go | 105 +++ .../managedhsmkeys/model_managedhsmaction.go | 8 + .../managedhsmkeys/model_managedhsmkey.go | 12 + .../model_managedhsmkeyattributes.go | 14 + .../model_managedhsmkeycreateparameters.go | 9 + .../model_managedhsmkeyproperties.go | 16 + .../model_managedhsmkeyreleasepolicy.go | 9 + ...l_managedhsmkeyrotationpolicyattributes.go | 10 + .../model_managedhsmlifetimeaction.go | 9 + .../model_managedhsmrotationpolicy.go | 9 + .../managedhsmkeys/model_managedhsmtrigger.go | 9 + .../2024-11-01/managedhsmkeys/predicates.go | 27 + .../2024-11-01/managedhsmkeys/version.go | 10 + .../keyvault/2024-11-01/managedhsms/README.md | 183 ++++ .../keyvault/2024-11-01/managedhsms/client.go | 26 + .../2024-11-01/managedhsms/constants.go | 603 ++++++++++++ .../managedhsms/id_deletedmanagedhsm.go | 130 +++ .../managedhsms/id_deletedmanagedhsm_test.go | 282 ++++++ .../2024-11-01/managedhsms/id_managedhsm.go | 130 +++ .../managedhsms/id_managedhsm_test.go | 282 ++++++ .../method_checkmhsmnameavailability.go | 59 ++ .../managedhsms/method_createorupdate.go | 75 ++ .../2024-11-01/managedhsms/method_delete.go | 71 ++ .../2024-11-01/managedhsms/method_get.go | 54 ++ .../managedhsms/method_getdeleted.go | 53 ++ .../managedhsms/method_listbyresourcegroup.go | 135 +++ .../managedhsms/method_listbysubscription.go | 135 +++ .../managedhsms/method_listdeleted.go | 106 +++ .../managedhsms/method_purgedeleted.go | 69 ++ .../2024-11-01/managedhsms/method_update.go | 75 ++ ...del_checkmhsmnameavailabilityparameters.go | 8 + .../model_checkmhsmnameavailabilityresult.go | 10 + .../managedhsms/model_deletedmanagedhsm.go | 11 + .../model_deletedmanagedhsmproperties.go | 43 + .../managedhsms/model_managedhsm.go | 21 + .../managedhsms/model_managedhsmproperties.go | 40 + ...odel_managedhsmsecuritydomainproperties.go | 9 + .../managedhsms/model_managedhsmsku.go | 9 + .../model_mhsmgeoreplicatedregion.go | 10 + .../managedhsms/model_mhsmiprule.go | 8 + .../managedhsms/model_mhsmnetworkruleset.go | 11 + .../managedhsms/model_mhsmprivateendpoint.go | 8 + ...model_mhsmprivateendpointconnectionitem.go | 10 + ...mhsmprivateendpointconnectionproperties.go | 10 + ...l_mhsmprivatelinkserviceconnectionstate.go | 10 + .../model_mhsmvirtualnetworkrule.go | 8 + .../2024-11-01/managedhsms/predicates.go | 55 ++ .../2024-11-01/managedhsms/version.go | 10 + .../README.md | 37 + .../client.go | 26 + .../constants.go | 239 +++++ .../id_managedhsm.go | 130 +++ .../id_managedhsm_test.go | 282 ++++++ ...rivateendpointconnectionslistbyresource.go | 105 +++ .../model_managedhsmsku.go | 9 + .../model_mhsmprivateendpoint.go | 8 + .../model_mhsmprivateendpointconnection.go | 22 + ...mhsmprivateendpointconnectionproperties.go | 10 + ...l_mhsmprivatelinkserviceconnectionstate.go | 10 + .../predicates.go | 37 + .../version.go | 10 + .../2024-11-01/mhsmlistregions/README.md | 37 + .../2024-11-01/mhsmlistregions/client.go | 26 + .../2024-11-01/mhsmlistregions/constants.go | 63 ++ .../mhsmlistregions/id_managedhsm.go | 130 +++ .../mhsmlistregions/id_managedhsm_test.go | 282 ++++++ .../method_mhsmregionslistbyresource.go | 105 +++ .../model_mhsmgeoreplicatedregion.go | 10 + .../2024-11-01/mhsmlistregions/predicates.go | 22 + .../2024-11-01/mhsmlistregions/version.go | 10 + .../mhsmprivateendpointconnections/README.md | 69 ++ .../mhsmprivateendpointconnections/client.go | 26 + .../constants.go | 239 +++++ .../id_privateendpointconnection.go | 139 +++ .../id_privateendpointconnection_test.go | 327 +++++++ .../method_delete.go | 72 ++ .../method_get.go | 53 ++ .../method_put.go | 57 ++ .../model_managedhsmsku.go | 9 + .../model_mhsmprivateendpoint.go | 8 + .../model_mhsmprivateendpointconnection.go | 22 + ...mhsmprivateendpointconnectionproperties.go | 10 + ...l_mhsmprivatelinkserviceconnectionstate.go | 10 + .../mhsmprivateendpointconnections/version.go | 10 + .../mhsmprivatelinkresources/README.md | 36 + .../mhsmprivatelinkresources/client.go | 26 + .../mhsmprivatelinkresources/constants.go | 101 ++ .../mhsmprivatelinkresources/id_managedhsm.go | 130 +++ .../id_managedhsm_test.go | 282 ++++++ .../method_listbymhsmresource.go | 54 ++ .../model_managedhsmsku.go | 9 + .../model_mhsmprivatelinkresource.go | 21 + ...model_mhsmprivatelinkresourcelistresult.go | 8 + ...model_mhsmprivatelinkresourceproperties.go | 10 + .../mhsmprivatelinkresources/version.go | 10 + .../privateendpointconnections/README.md | 87 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 148 +++ .../method_delete.go | 73 ++ .../privateendpointconnections/method_get.go | 55 ++ .../method_listbyresource.go | 106 +++ .../privateendpointconnections/method_put.go | 58 ++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 14 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/predicates.go | 37 + .../privateendpointconnections/version.go | 10 + .../2024-11-01/privatelinkresources/README.md | 37 + .../2024-11-01/privatelinkresources/client.go | 26 + .../method_listbyvault.go | 55 ++ .../model_privatelinkresource.go | 13 + .../model_privatelinkresourcelistresult.go | 8 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/version.go | 10 + .../keyvault/2024-11-01/secrets/README.md | 96 ++ .../keyvault/2024-11-01/secrets/client.go | 26 + .../keyvault/2024-11-01/secrets/id_secret.go | 139 +++ .../2024-11-01/secrets/id_secret_test.go | 327 +++++++ .../secrets/method_createorupdate.go | 58 ++ .../keyvault/2024-11-01/secrets/method_get.go | 53 ++ .../2024-11-01/secrets/method_list.go | 135 +++ .../2024-11-01/secrets/method_update.go | 58 ++ .../2024-11-01/secrets/model_attributes.go | 12 + .../2024-11-01/secrets/model_secret.go | 13 + .../model_secretcreateorupdateparameters.go | 9 + .../secrets/model_secretpatchparameters.go | 9 + .../secrets/model_secretpatchproperties.go | 10 + .../secrets/model_secretproperties.go | 12 + .../keyvault/2024-11-01/secrets/predicates.go | 32 + .../keyvault/2024-11-01/secrets/version.go | 10 + .../keyvault/2024-11-01/vaults/README.md | 229 +++++ .../keyvault/2024-11-01/vaults/client.go | 26 + .../keyvault/2024-11-01/vaults/constants.go | 878 ++++++++++++++++++ .../2024-11-01/vaults/id_deletedvault.go | 130 +++ .../2024-11-01/vaults/id_deletedvault_test.go | 282 ++++++ .../2024-11-01/vaults/id_operationkind.go | 147 +++ .../vaults/id_operationkind_test.go | 327 +++++++ .../vaults/method_checknameavailability.go | 59 ++ .../vaults/method_createorupdate.go | 76 ++ .../2024-11-01/vaults/method_delete.go | 48 + .../keyvault/2024-11-01/vaults/method_get.go | 54 ++ .../2024-11-01/vaults/method_getdeleted.go | 53 ++ .../keyvault/2024-11-01/vaults/method_list.go | 139 +++ .../vaults/method_listbyresourcegroup.go | 135 +++ .../vaults/method_listbysubscription.go | 135 +++ .../2024-11-01/vaults/method_listdeleted.go | 106 +++ .../2024-11-01/vaults/method_purgedeleted.go | 70 ++ .../2024-11-01/vaults/method_update.go | 59 ++ .../vaults/method_updateaccesspolicy.go | 58 ++ .../vaults/model_accesspolicyentry.go | 11 + .../model_checknameavailabilityresult.go | 10 + .../2024-11-01/vaults/model_deletedvault.go | 11 + .../vaults/model_deletedvaultproperties.go | 43 + .../2024-11-01/vaults/model_iprule.go | 8 + .../2024-11-01/vaults/model_networkruleset.go | 11 + .../2024-11-01/vaults/model_permissions.go | 11 + .../vaults/model_privateendpoint.go | 8 + .../model_privateendpointconnectionitem.go | 10 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../2024-11-01/vaults/model_resource.go | 12 + .../keyvault/2024-11-01/vaults/model_sku.go | 9 + .../keyvault/2024-11-01/vaults/model_vault.go | 18 + .../model_vaultaccesspolicyparameters.go | 12 + .../model_vaultaccesspolicyproperties.go | 8 + ...el_vaultchecknameavailabilityparameters.go | 9 + .../model_vaultcreateorupdateparameters.go | 10 + .../vaults/model_vaultpatchparameters.go | 9 + .../vaults/model_vaultpatchproperties.go | 20 + .../vaults/model_vaultproperties.go | 24 + .../vaults/model_virtualnetworkrule.go | 9 + .../keyvault/2024-11-01/vaults/predicates.go | 83 ++ .../keyvault/2024-11-01/vaults/version.go | 10 + .../managedidentity/2024-11-30/client.go | 28 + .../2024-11-30/managedidentities/README.md | 215 +++++ .../2024-11-30/managedidentities/client.go | 26 + .../2024-11-30/managedidentities/constants.go | 51 + .../id_federatedidentitycredential.go | 139 +++ .../id_federatedidentitycredential_test.go | 327 +++++++ ...eratedidentitycredentialscreateorupdate.go | 58 ++ ...thod_federatedidentitycredentialsdelete.go | 47 + .../method_federatedidentitycredentialsget.go | 53 ++ ...method_federatedidentitycredentialslist.go | 135 +++ ...thod_systemassignedidentitiesgetbyscope.go | 55 ++ ...od_userassignedidentitiescreateorupdate.go | 59 ++ .../method_userassignedidentitiesdelete.go | 48 + .../method_userassignedidentitiesget.go | 54 ++ ...erassignedidentitieslistbyresourcegroup.go | 106 +++ ...serassignedidentitieslistbysubscription.go | 106 +++ .../method_userassignedidentitiesupdate.go | 58 ++ .../model_federatedidentitycredential.go | 16 + ...l_federatedidentitycredentialproperties.go | 10 + .../managedidentities/model_identity.go | 18 + .../managedidentities/model_identityupdate.go | 18 + .../model_systemassignedidentity.go | 18 + .../model_systemassignedidentityproperties.go | 11 + .../model_userassignedidentityproperties.go | 11 + .../managedidentities/predicates.go | 55 ++ .../2024-11-30/managedidentities/version.go | 10 + resource-manager/quota/2025-03-01/client.go | 109 +++ .../groupquotalimitrequest/README.md | 53 ++ .../groupquotalimitrequest/client.go | 26 + .../groupquotalimitrequest/constants.go | 66 ++ .../id_groupquotarequest.go | 132 +++ .../id_groupquotarequest_test.go | 312 +++++++ .../id_resourceprovider.go | 132 +++ .../id_resourceprovider_test.go | 312 +++++++ .../method_groupquotalimitsrequestget.go | 53 ++ .../method_groupquotalimitsrequestlist.go | 134 +++ .../model_groupquotarequestbase.go | 8 + .../model_groupquotarequestbaseproperties.go | 11 + ...del_groupquotarequestbasepropertiesname.go | 9 + .../model_submittedresourcerequeststatus.go | 16 + ...ubmittedresourcerequeststatusproperties.go | 29 + .../groupquotalimitrequest/predicates.go | 27 + .../groupquotalimitrequest/version.go | 10 + .../2025-03-01/groupquotalimits/README.md | 53 ++ .../2025-03-01/groupquotalimits/client.go | 26 + .../2025-03-01/groupquotalimits/constants.go | 66 ++ .../groupquotalimits/id_groupquotalimit.go | 141 +++ .../id_groupquotalimit_test.go | 357 +++++++ .../groupquotalimits/method_list.go | 53 ++ .../groupquotalimits/method_requestupdate.go | 75 ++ .../model_allocatedquotatosubscriptionlist.go | 8 + .../model_allocatedtosubscription.go | 9 + .../model_groupquotadetails.go | 14 + .../model_groupquotadetailsname.go | 9 + .../groupquotalimits/model_groupquotalimit.go | 8 + .../model_groupquotalimitlist.go | 16 + .../model_groupquotalimitlistproperties.go | 10 + .../2025-03-01/groupquotalimits/version.go | 10 + .../quota/2025-03-01/groupquotas/README.md | 100 ++ .../quota/2025-03-01/groupquotas/client.go | 26 + .../quota/2025-03-01/groupquotas/constants.go | 66 ++ .../2025-03-01/groupquotas/id_groupquota.go | 123 +++ .../groupquotas/id_groupquota_test.go | 267 ++++++ .../groupquotas/method_createorupdate.go | 75 ++ .../2025-03-01/groupquotas/method_delete.go | 70 ++ .../2025-03-01/groupquotas/method_get.go | 53 ++ .../2025-03-01/groupquotas/method_list.go | 106 +++ .../2025-03-01/groupquotas/method_update.go | 75 ++ .../groupquotas/model_groupquotasentity.go | 16 + .../model_groupquotasentitybase.go | 9 + .../model_groupquotasentitybasepatch.go | 9 + .../model_groupquotasentitypatch.go | 16 + .../2025-03-01/groupquotas/predicates.go | 27 + .../quota/2025-03-01/groupquotas/version.go | 10 + .../groupquotassubscriptions/README.md | 89 ++ .../groupquotassubscriptions/client.go | 26 + .../groupquotassubscriptions/constants.go | 66 ++ .../groupquotassubscriptions/id_groupquota.go | 123 +++ .../id_groupquota_test.go | 267 ++++++ .../id_subscription.go | 132 +++ .../id_subscription_test.go | 312 +++++++ ...d_groupquotasubscriptionscreateorupdate.go | 71 ++ .../method_groupquotasubscriptionsdelete.go | 70 ++ .../method_groupquotasubscriptionsget.go | 53 ++ .../method_groupquotasubscriptionslist.go | 105 +++ .../method_groupquotasubscriptionsupdate.go | 71 ++ .../model_groupquotasubscriptionid.go | 16 + ...odel_groupquotasubscriptionidproperties.go | 9 + .../groupquotassubscriptions/predicates.go | 27 + .../groupquotassubscriptions/version.go | 10 + .../groupquotasubscriptionrequests/README.md | 53 ++ .../groupquotasubscriptionrequests/client.go | 26 + .../constants.go | 66 ++ .../id_groupquota.go | 123 +++ .../id_groupquota_test.go | 267 ++++++ .../id_subscriptionrequest.go | 132 +++ .../id_subscriptionrequest_test.go | 312 +++++++ .../method_get.go | 53 ++ .../method_list.go | 105 +++ ...del_groupquotasubscriptionrequeststatus.go | 16 + ...uotasubscriptionrequeststatusproperties.go | 28 + .../predicates.go | 27 + .../groupquotasubscriptionrequests/version.go | 10 + .../2025-03-01/quotainformation/README.md | 88 ++ .../2025-03-01/quotainformation/client.go | 26 + .../2025-03-01/quotainformation/constants.go | 89 ++ .../quotainformation/id_scopedquota.go | 120 +++ .../quotainformation/id_scopedquota_test.go | 222 +++++ .../method_quotacreateorupdate.go | 75 ++ .../quotainformation/method_quotaget.go | 53 ++ .../quotainformation/method_quotalist.go | 106 +++ .../quotainformation/method_quotaupdate.go | 75 ++ .../model_currentquotalimitbase.go | 11 + .../quotainformation/model_limitjsonobject.go | 75 ++ .../quotainformation/model_limitobject.go | 51 + .../quotainformation/model_quotaproperties.go | 57 ++ .../quotainformation/model_resourcename.go | 9 + .../2025-03-01/quotainformation/predicates.go | 27 + .../2025-03-01/quotainformation/version.go | 10 + .../quota/2025-03-01/quotarequests/README.md | 54 ++ .../quota/2025-03-01/quotarequests/client.go | 26 + .../2025-03-01/quotarequests/constants.go | 139 +++ .../quotarequests/id_scopedquotarequest.go | 120 +++ .../id_scopedquotarequest_test.go | 222 +++++ .../quotarequests/method_tatusget.go | 53 ++ .../quotarequests/method_tatuslist.go | 139 +++ .../quotarequests/model_limitjsonobject.go | 75 ++ .../quotarequests/model_limitobject.go | 51 + .../model_quotarequestdetails.go | 11 + .../model_quotarequestproperties.go | 30 + .../quotarequests/model_resourcename.go | 9 + .../quotarequests/model_serviceerrordetail.go | 9 + .../quotarequests/model_subrequest.go | 57 ++ .../2025-03-01/quotarequests/predicates.go | 27 + .../quota/2025-03-01/quotarequests/version.go | 10 + .../subscriptionquotaallocation/README.md | 53 ++ .../subscriptionquotaallocation/client.go | 26 + .../subscriptionquotaallocation/constants.go | 66 ++ .../id_quotaallocation.go | 150 +++ .../id_quotaallocation_test.go | 402 ++++++++ ...od_groupquotasubscriptionallocationlist.go | 53 ++ ...uotasubscriptionallocationrequestupdate.go | 75 ++ .../model_subscriptionquotaallocations.go | 8 + .../model_subscriptionquotaallocationslist.go | 16 + ...scriptionquotaallocationslistproperties.go | 10 + .../model_subscriptionquotadetails.go | 11 + .../model_subscriptionquotadetailsname.go | 9 + .../subscriptionquotaallocation/version.go | 10 + .../README.md | 53 ++ .../client.go | 26 + .../constants.go | 66 ++ .../id_groupquotaresourceprovider.go | 141 +++ .../id_groupquotaresourceprovider_test.go | 357 +++++++ .../id_quotaallocationrequest.go | 150 +++ .../id_quotaallocationrequest_test.go | 402 ++++++++ ...upquotasubscriptionallocationrequestget.go | 53 ++ ...pquotasubscriptionallocationrequestlist.go | 134 +++ .../model_quotaallocationrequestbase.go | 8 + ...el_quotaallocationrequestbaseproperties.go | 10 + ...uotaallocationrequestbasepropertiesname.go | 9 + .../model_quotaallocationrequeststatus.go | 16 + ..._quotaallocationrequeststatusproperties.go | 29 + .../predicates.go | 27 + .../version.go | 10 + .../2025-03-01/usagesinformation/README.md | 54 ++ .../2025-03-01/usagesinformation/client.go | 26 + .../2025-03-01/usagesinformation/constants.go | 51 + .../usagesinformation/id_scopedusage.go | 120 +++ .../usagesinformation/id_scopedusage_test.go | 222 +++++ .../usagesinformation/method_usagesget.go | 53 ++ .../usagesinformation/method_usageslist.go | 106 +++ .../model_currentusagesbase.go | 11 + .../usagesinformation/model_resourcename.go | 9 + .../usagesinformation/model_usagesobject.go | 9 + .../model_usagesproperties.go | 14 + .../usagesinformation/predicates.go | 27 + .../2025-03-01/usagesinformation/version.go | 10 + 497 files changed, 36151 insertions(+) create mode 100644 resource-manager/dashboard/2024-10-01/client.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/README.md create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/client.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/method_grafanafetchavailableplugins.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/model_grafanaavailableplugin.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaplugin/version.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/README.md create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/client.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/constants.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacheckenterprisedetails.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacreate.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanadelete.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaget.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalist.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalistbyresourcegroup.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaupdate.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_azuremonitorworkspaceintegration.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_enterpriseconfigurations.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_enterprisedetails.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaconfigurations.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaintegrations.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaplugin.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafana.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanapropertiesupdateparameters.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaupdateparameters.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_marketplacetrialquota.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpoint.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnection.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_resourcesku.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_saassubscriptiondetails.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_security.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_smtp.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_snapshots.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_subscriptionterm.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/model_users.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/grafanaresource/version.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/README.md create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/client.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/constants.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric_test.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/method_create.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/method_delete.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/method_get.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/method_list.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/method_update.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabric.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricpropertiesupdateparameters.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricupdateparameters.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/integrationfabric/version.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/README.md create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/client.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/constants.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint_test.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_create.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_delete.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_get.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_list.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_refresh.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_update.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodel.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/managedprivateendpoints/version.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/README.md create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/client.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/constants.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection_test.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/method_approve.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/method_delete.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/method_get.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/method_list.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpoint.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnection.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/privateendpointconnection/version.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/README.md create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/client.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/constants.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana_test.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource_test.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/method_get.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/method_list.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresource.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresourceproperties.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/predicates.go create mode 100644 resource-manager/dashboard/2024-10-01/privatelinkresource/version.go create mode 100644 resource-manager/keyvault/2024-11-01/client.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/README.md create mode 100644 resource-manager/keyvault/2024-11-01/keys/client.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/method_createifnotexist.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/method_getversion.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/method_list.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/method_listversions.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_action.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_key.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_keyattributes.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_keycreateparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_keyproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_keyreleasepolicy.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_keyrotationpolicyattributes.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_lifetimeaction.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_rotationpolicy.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/model_trigger.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/keys/version.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/README.md create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/client.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key_test.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version_test.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/method_createifnotexist.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/method_getversion.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/method_list.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/method_listversions.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmaction.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkey.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyattributes.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeycreateparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyreleasepolicy.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyrotationpolicyattributes.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmlifetimeaction.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmrotationpolicy.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmtrigger.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsmkeys/version.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/README.md create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/client.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_checkmhsmnameavailability.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_createorupdate.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_delete.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_getdeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_listbyresourcegroup.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_listbysubscription.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_listdeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_purgedeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/method_update.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityresult.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsmproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsecuritydomainproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsku.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmgeoreplicatedregion.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmiprule.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmnetworkruleset.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpoint.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionitem.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivatelinkserviceconnectionstate.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmvirtualnetworkrule.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/managedhsms/version.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/README.md create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/client.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/method_mhsmprivateendpointconnectionslistbyresource.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_managedhsmsku.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpoint.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnection.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/version.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/README.md create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/client.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/method_mhsmregionslistbyresource.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/model_mhsmgeoreplicatedregion.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmlistregions/version.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/README.md create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/client.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_delete.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_put.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_managedhsmsku.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpoint.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnection.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/version.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/README.md create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/client.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm_test.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/method_listbymhsmresource.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_managedhsmsku.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresource.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourcelistresult.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourceproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/version.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/README.md create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/client.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/method_delete.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/method_listbyresource.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/method_put.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/privateendpointconnections/version.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/README.md create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/client.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/method_listbyvault.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/privatelinkresources/version.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/README.md create mode 100644 resource-manager/keyvault/2024-11-01/secrets/client.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/id_secret.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/id_secret_test.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/method_createorupdate.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/method_list.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/method_update.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_attributes.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_secret.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_secretcreateorupdateparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_secretpatchparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_secretpatchproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/model_secretproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/secrets/version.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/README.md create mode 100644 resource-manager/keyvault/2024-11-01/vaults/client.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/constants.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/id_deletedvault.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/id_deletedvault_test.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/id_operationkind.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/id_operationkind_test.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_checknameavailability.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_createorupdate.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_delete.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_get.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_getdeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_list.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_listbyresourcegroup.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_listbysubscription.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_listdeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_purgedeleted.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_update.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/method_updateaccesspolicy.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_accesspolicyentry.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_checknameavailabilityresult.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_deletedvault.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_deletedvaultproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_iprule.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_networkruleset.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_permissions.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_privateendpoint.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionitem.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_resource.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_sku.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vault.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultchecknameavailabilityparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultcreateorupdateparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchparameters.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_vaultproperties.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/model_virtualnetworkrule.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/predicates.go create mode 100644 resource-manager/keyvault/2024-11-01/vaults/version.go create mode 100644 resource-manager/managedidentity/2024-11-30/client.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/README.md create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/client.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/constants.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential_test.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialscreateorupdate.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsdelete.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsget.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialslist.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_systemassignedidentitiesgetbyscope.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiescreateorupdate.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesdelete.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesget.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbyresourcegroup.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbysubscription.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesupdate.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredential.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredentialproperties.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_identity.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_identityupdate.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentity.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentityproperties.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/model_userassignedidentityproperties.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/predicates.go create mode 100644 resource-manager/managedidentity/2024-11-30/managedidentities/version.go create mode 100644 resource-manager/quota/2025-03-01/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/README.md create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/constants.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestget.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestlist.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbase.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbaseproperties.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbasepropertiesname.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatus.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatusproperties.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/predicates.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimitrequest/version.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/README.md create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/constants.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/method_list.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/method_requestupdate.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedquotatosubscriptionlist.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedtosubscription.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetails.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetailsname.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimit.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlist.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlistproperties.go create mode 100644 resource-manager/quota/2025-03-01/groupquotalimits/version.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/README.md create mode 100644 resource-manager/quota/2025-03-01/groupquotas/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/constants.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/id_groupquota.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/id_groupquota_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/method_createorupdate.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/method_delete.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/method_get.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/method_list.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/method_update.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentity.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybase.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybasepatch.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitypatch.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/predicates.go create mode 100644 resource-manager/quota/2025-03-01/groupquotas/version.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/README.md create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/constants.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionscreateorupdate.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsdelete.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsget.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionslist.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsupdate.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionid.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionidproperties.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/predicates.go create mode 100644 resource-manager/quota/2025-03-01/groupquotassubscriptions/version.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/README.md create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/client.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/constants.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest_test.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_get.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_list.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatus.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatusproperties.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/predicates.go create mode 100644 resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/version.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/README.md create mode 100644 resource-manager/quota/2025-03-01/quotainformation/client.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/constants.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/id_scopedquota.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/id_scopedquota_test.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/method_quotacreateorupdate.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/method_quotaget.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/method_quotalist.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/method_quotaupdate.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/model_currentquotalimitbase.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/model_limitjsonobject.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/model_limitobject.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/model_quotaproperties.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/model_resourcename.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/predicates.go create mode 100644 resource-manager/quota/2025-03-01/quotainformation/version.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/README.md create mode 100644 resource-manager/quota/2025-03-01/quotarequests/client.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/constants.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest_test.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/method_tatusget.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/method_tatuslist.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_limitjsonobject.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_limitobject.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_quotarequestdetails.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_quotarequestproperties.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_resourcename.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_serviceerrordetail.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/model_subrequest.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/predicates.go create mode 100644 resource-manager/quota/2025-03-01/quotarequests/version.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/README.md create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/client.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/constants.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation_test.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationlist.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationrequestupdate.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocations.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslist.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslistproperties.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetails.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetailsname.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocation/version.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/README.md create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/client.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/constants.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider_test.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest_test.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestget.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestlist.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbase.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbaseproperties.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbasepropertiesname.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatus.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatusproperties.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/predicates.go create mode 100644 resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/version.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/README.md create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/client.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/constants.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage_test.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/method_usagesget.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/method_usageslist.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/model_currentusagesbase.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/model_resourcename.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/model_usagesobject.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/model_usagesproperties.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/predicates.go create mode 100644 resource-manager/quota/2025-03-01/usagesinformation/version.go diff --git a/resource-manager/dashboard/2024-10-01/client.go b/resource-manager/dashboard/2024-10-01/client.go new file mode 100644 index 00000000000..afa21b09a72 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/client.go @@ -0,0 +1,73 @@ +package v2024_10_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaplugin" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/integrationfabric" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/managedprivateendpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privateendpointconnection" + "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privatelinkresource" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + GrafanaPlugin *grafanaplugin.GrafanaPluginClient + GrafanaResource *grafanaresource.GrafanaResourceClient + IntegrationFabric *integrationfabric.IntegrationFabricClient + ManagedPrivateEndpoints *managedprivateendpoints.ManagedPrivateEndpointsClient + PrivateEndpointConnection *privateendpointconnection.PrivateEndpointConnectionClient + PrivateLinkResource *privatelinkresource.PrivateLinkResourceClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + grafanaPluginClient, err := grafanaplugin.NewGrafanaPluginClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GrafanaPlugin client: %+v", err) + } + configureFunc(grafanaPluginClient.Client) + + grafanaResourceClient, err := grafanaresource.NewGrafanaResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GrafanaResource client: %+v", err) + } + configureFunc(grafanaResourceClient.Client) + + integrationFabricClient, err := integrationfabric.NewIntegrationFabricClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IntegrationFabric client: %+v", err) + } + configureFunc(integrationFabricClient.Client) + + managedPrivateEndpointsClient, err := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedPrivateEndpoints client: %+v", err) + } + configureFunc(managedPrivateEndpointsClient.Client) + + privateEndpointConnectionClient, err := privateendpointconnection.NewPrivateEndpointConnectionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnection client: %+v", err) + } + configureFunc(privateEndpointConnectionClient.Client) + + privateLinkResourceClient, err := privatelinkresource.NewPrivateLinkResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResource client: %+v", err) + } + configureFunc(privateLinkResourceClient.Client) + + return &Client{ + GrafanaPlugin: grafanaPluginClient, + GrafanaResource: grafanaResourceClient, + IntegrationFabric: integrationFabricClient, + ManagedPrivateEndpoints: managedPrivateEndpointsClient, + PrivateEndpointConnection: privateEndpointConnectionClient, + PrivateLinkResource: privateLinkResourceClient, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/README.md b/resource-manager/dashboard/2024-10-01/grafanaplugin/README.md new file mode 100644 index 00000000000..472a5c1c7bd --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaplugin` Documentation + +The `grafanaplugin` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaplugin" +``` + + +### Client Initialization + +```go +client := grafanaplugin.NewGrafanaPluginClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GrafanaPluginClient.GrafanaFetchAvailablePlugins` + +```go +ctx := context.TODO() +id := grafanaplugin.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.GrafanaFetchAvailablePlugins(ctx, id)` can be used to do batched pagination +items, err := client.GrafanaFetchAvailablePluginsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/client.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/client.go new file mode 100644 index 00000000000..d5366691666 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/client.go @@ -0,0 +1,26 @@ +package grafanaplugin + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaPluginClient struct { + Client *resourcemanager.Client +} + +func NewGrafanaPluginClientWithBaseURI(sdkApi sdkEnv.Api) (*GrafanaPluginClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "grafanaplugin", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GrafanaPluginClient: %+v", err) + } + + return &GrafanaPluginClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana.go new file mode 100644 index 00000000000..dd5d468bfdf --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana.go @@ -0,0 +1,130 @@ +package grafanaplugin + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana_test.go new file mode 100644 index 00000000000..9c151609189 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/id_grafana_test.go @@ -0,0 +1,282 @@ +package grafanaplugin + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/method_grafanafetchavailableplugins.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/method_grafanafetchavailableplugins.go new file mode 100644 index 00000000000..84652c0c456 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/method_grafanafetchavailableplugins.go @@ -0,0 +1,105 @@ +package grafanaplugin + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaFetchAvailablePluginsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GrafanaAvailablePlugin +} + +type GrafanaFetchAvailablePluginsCompleteResult struct { + LatestHttpResponse *http.Response + Items []GrafanaAvailablePlugin +} + +type GrafanaFetchAvailablePluginsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GrafanaFetchAvailablePluginsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GrafanaFetchAvailablePlugins ... +func (c GrafanaPluginClient) GrafanaFetchAvailablePlugins(ctx context.Context, id GrafanaId) (result GrafanaFetchAvailablePluginsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &GrafanaFetchAvailablePluginsCustomPager{}, + Path: fmt.Sprintf("%s/fetchAvailablePlugins", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GrafanaAvailablePlugin `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GrafanaFetchAvailablePluginsComplete retrieves all the results into a single object +func (c GrafanaPluginClient) GrafanaFetchAvailablePluginsComplete(ctx context.Context, id GrafanaId) (GrafanaFetchAvailablePluginsCompleteResult, error) { + return c.GrafanaFetchAvailablePluginsCompleteMatchingPredicate(ctx, id, GrafanaAvailablePluginOperationPredicate{}) +} + +// GrafanaFetchAvailablePluginsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GrafanaPluginClient) GrafanaFetchAvailablePluginsCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate GrafanaAvailablePluginOperationPredicate) (result GrafanaFetchAvailablePluginsCompleteResult, err error) { + items := make([]GrafanaAvailablePlugin, 0) + + resp, err := c.GrafanaFetchAvailablePlugins(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GrafanaFetchAvailablePluginsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/model_grafanaavailableplugin.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/model_grafanaavailableplugin.go new file mode 100644 index 00000000000..f5937a1cbfc --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/model_grafanaavailableplugin.go @@ -0,0 +1,9 @@ +package grafanaplugin + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaAvailablePlugin struct { + Name *string `json:"name,omitempty"` + PluginId *string `json:"pluginId,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/predicates.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/predicates.go new file mode 100644 index 00000000000..343481cd12b --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/predicates.go @@ -0,0 +1,22 @@ +package grafanaplugin + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaAvailablePluginOperationPredicate struct { + Name *string + PluginId *string +} + +func (p GrafanaAvailablePluginOperationPredicate) Matches(input GrafanaAvailablePlugin) bool { + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.PluginId != nil && (input.PluginId == nil || *p.PluginId != *input.PluginId) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaplugin/version.go b/resource-manager/dashboard/2024-10-01/grafanaplugin/version.go new file mode 100644 index 00000000000..80af09c57a2 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaplugin/version.go @@ -0,0 +1,10 @@ +package grafanaplugin + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/grafanaplugin/2024-10-01" +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/README.md b/resource-manager/dashboard/2024-10-01/grafanaresource/README.md new file mode 100644 index 00000000000..2eff1384d7d --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/README.md @@ -0,0 +1,137 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaresource` Documentation + +The `grafanaresource` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/grafanaresource" +``` + + +### Client Initialization + +```go +client := grafanaresource.NewGrafanaResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaCheckEnterpriseDetails` + +```go +ctx := context.TODO() +id := grafanaresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +read, err := client.GrafanaCheckEnterpriseDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaCreate` + +```go +ctx := context.TODO() +id := grafanaresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +payload := grafanaresource.ManagedGrafana{ + // ... +} + + +if err := client.GrafanaCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaDelete` + +```go +ctx := context.TODO() +id := grafanaresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +if err := client.GrafanaDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaGet` + +```go +ctx := context.TODO() +id := grafanaresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +read, err := client.GrafanaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.GrafanaList(ctx, id)` can be used to do batched pagination +items, err := client.GrafanaListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.GrafanaListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.GrafanaListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GrafanaResourceClient.GrafanaUpdate` + +```go +ctx := context.TODO() +id := grafanaresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +payload := grafanaresource.ManagedGrafanaUpdateParameters{ + // ... +} + + +read, err := client.GrafanaUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/client.go b/resource-manager/dashboard/2024-10-01/grafanaresource/client.go new file mode 100644 index 00000000000..e4df7c7aa8b --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/client.go @@ -0,0 +1,26 @@ +package grafanaresource + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaResourceClient struct { + Client *resourcemanager.Client +} + +func NewGrafanaResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*GrafanaResourceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "grafanaresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GrafanaResourceClient: %+v", err) + } + + return &GrafanaResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/constants.go b/resource-manager/dashboard/2024-10-01/grafanaresource/constants.go new file mode 100644 index 00000000000..e46c274b061 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/constants.go @@ -0,0 +1,491 @@ +package grafanaresource + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiKey string + +const ( + ApiKeyDisabled ApiKey = "Disabled" + ApiKeyEnabled ApiKey = "Enabled" +) + +func PossibleValuesForApiKey() []string { + return []string{ + string(ApiKeyDisabled), + string(ApiKeyEnabled), + } +} + +func (s *ApiKey) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiKey(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiKey(input string) (*ApiKey, error) { + vals := map[string]ApiKey{ + "disabled": ApiKeyDisabled, + "enabled": ApiKeyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiKey(input) + return &out, nil +} + +type AutoGeneratedDomainNameLabelScope string + +const ( + AutoGeneratedDomainNameLabelScopeTenantReuse AutoGeneratedDomainNameLabelScope = "TenantReuse" +) + +func PossibleValuesForAutoGeneratedDomainNameLabelScope() []string { + return []string{ + string(AutoGeneratedDomainNameLabelScopeTenantReuse), + } +} + +func (s *AutoGeneratedDomainNameLabelScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoGeneratedDomainNameLabelScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoGeneratedDomainNameLabelScope(input string) (*AutoGeneratedDomainNameLabelScope, error) { + vals := map[string]AutoGeneratedDomainNameLabelScope{ + "tenantreuse": AutoGeneratedDomainNameLabelScopeTenantReuse, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoGeneratedDomainNameLabelScope(input) + return &out, nil +} + +type AvailablePromotion string + +const ( + AvailablePromotionFreeTrial AvailablePromotion = "FreeTrial" + AvailablePromotionNone AvailablePromotion = "None" +) + +func PossibleValuesForAvailablePromotion() []string { + return []string{ + string(AvailablePromotionFreeTrial), + string(AvailablePromotionNone), + } +} + +func (s *AvailablePromotion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAvailablePromotion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAvailablePromotion(input string) (*AvailablePromotion, error) { + vals := map[string]AvailablePromotion{ + "freetrial": AvailablePromotionFreeTrial, + "none": AvailablePromotionNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AvailablePromotion(input) + return &out, nil +} + +type DeterministicOutboundIP string + +const ( + DeterministicOutboundIPDisabled DeterministicOutboundIP = "Disabled" + DeterministicOutboundIPEnabled DeterministicOutboundIP = "Enabled" +) + +func PossibleValuesForDeterministicOutboundIP() []string { + return []string{ + string(DeterministicOutboundIPDisabled), + string(DeterministicOutboundIPEnabled), + } +} + +func (s *DeterministicOutboundIP) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeterministicOutboundIP(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeterministicOutboundIP(input string) (*DeterministicOutboundIP, error) { + vals := map[string]DeterministicOutboundIP{ + "disabled": DeterministicOutboundIPDisabled, + "enabled": DeterministicOutboundIPEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeterministicOutboundIP(input) + return &out, nil +} + +type MarketplaceAutoRenew string + +const ( + MarketplaceAutoRenewDisabled MarketplaceAutoRenew = "Disabled" + MarketplaceAutoRenewEnabled MarketplaceAutoRenew = "Enabled" +) + +func PossibleValuesForMarketplaceAutoRenew() []string { + return []string{ + string(MarketplaceAutoRenewDisabled), + string(MarketplaceAutoRenewEnabled), + } +} + +func (s *MarketplaceAutoRenew) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMarketplaceAutoRenew(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMarketplaceAutoRenew(input string) (*MarketplaceAutoRenew, error) { + vals := map[string]MarketplaceAutoRenew{ + "disabled": MarketplaceAutoRenewDisabled, + "enabled": MarketplaceAutoRenewEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MarketplaceAutoRenew(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type StartTLSPolicy string + +const ( + StartTLSPolicyMandatoryStartTLS StartTLSPolicy = "MandatoryStartTLS" + StartTLSPolicyNoStartTLS StartTLSPolicy = "NoStartTLS" + StartTLSPolicyOpportunisticStartTLS StartTLSPolicy = "OpportunisticStartTLS" +) + +func PossibleValuesForStartTLSPolicy() []string { + return []string{ + string(StartTLSPolicyMandatoryStartTLS), + string(StartTLSPolicyNoStartTLS), + string(StartTLSPolicyOpportunisticStartTLS), + } +} + +func (s *StartTLSPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStartTLSPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStartTLSPolicy(input string) (*StartTLSPolicy, error) { + vals := map[string]StartTLSPolicy{ + "mandatorystarttls": StartTLSPolicyMandatoryStartTLS, + "nostarttls": StartTLSPolicyNoStartTLS, + "opportunisticstarttls": StartTLSPolicyOpportunisticStartTLS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StartTLSPolicy(input) + return &out, nil +} + +type ZoneRedundancy string + +const ( + ZoneRedundancyDisabled ZoneRedundancy = "Disabled" + ZoneRedundancyEnabled ZoneRedundancy = "Enabled" +) + +func PossibleValuesForZoneRedundancy() []string { + return []string{ + string(ZoneRedundancyDisabled), + string(ZoneRedundancyEnabled), + } +} + +func (s *ZoneRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseZoneRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseZoneRedundancy(input string) (*ZoneRedundancy, error) { + vals := map[string]ZoneRedundancy{ + "disabled": ZoneRedundancyDisabled, + "enabled": ZoneRedundancyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ZoneRedundancy(input) + return &out, nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana.go b/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana.go new file mode 100644 index 00000000000..96ad1bf2caf --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana.go @@ -0,0 +1,130 @@ +package grafanaresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana_test.go new file mode 100644 index 00000000000..438f98758b9 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/id_grafana_test.go @@ -0,0 +1,282 @@ +package grafanaresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacheckenterprisedetails.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacheckenterprisedetails.go new file mode 100644 index 00000000000..2a5fca2d796 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacheckenterprisedetails.go @@ -0,0 +1,54 @@ +package grafanaresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaCheckEnterpriseDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnterpriseDetails +} + +// GrafanaCheckEnterpriseDetails ... +func (c GrafanaResourceClient) GrafanaCheckEnterpriseDetails(ctx context.Context, id GrafanaId) (result GrafanaCheckEnterpriseDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkEnterpriseDetails", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model EnterpriseDetails + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacreate.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacreate.go new file mode 100644 index 00000000000..e520ad8a931 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanacreate.go @@ -0,0 +1,75 @@ +package grafanaresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedGrafana +} + +// GrafanaCreate ... +func (c GrafanaResourceClient) GrafanaCreate(ctx context.Context, id GrafanaId, input ManagedGrafana) (result GrafanaCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GrafanaCreateThenPoll performs GrafanaCreate then polls until it's completed +func (c GrafanaResourceClient) GrafanaCreateThenPoll(ctx context.Context, id GrafanaId, input ManagedGrafana) error { + result, err := c.GrafanaCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GrafanaCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GrafanaCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanadelete.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanadelete.go new file mode 100644 index 00000000000..f382b6af39a --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanadelete.go @@ -0,0 +1,71 @@ +package grafanaresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// GrafanaDelete ... +func (c GrafanaResourceClient) GrafanaDelete(ctx context.Context, id GrafanaId) (result GrafanaDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GrafanaDeleteThenPoll performs GrafanaDelete then polls until it's completed +func (c GrafanaResourceClient) GrafanaDeleteThenPoll(ctx context.Context, id GrafanaId) error { + result, err := c.GrafanaDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing GrafanaDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GrafanaDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaget.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaget.go new file mode 100644 index 00000000000..f1371abbec4 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaget.go @@ -0,0 +1,53 @@ +package grafanaresource + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedGrafana +} + +// GrafanaGet ... +func (c GrafanaResourceClient) GrafanaGet(ctx context.Context, id GrafanaId) (result GrafanaGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedGrafana + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalist.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalist.go new file mode 100644 index 00000000000..f1f91aeb8e4 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalist.go @@ -0,0 +1,106 @@ +package grafanaresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedGrafana +} + +type GrafanaListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedGrafana +} + +type GrafanaListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GrafanaListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GrafanaList ... +func (c GrafanaResourceClient) GrafanaList(ctx context.Context, id commonids.SubscriptionId) (result GrafanaListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GrafanaListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Dashboard/grafana", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedGrafana `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GrafanaListComplete retrieves all the results into a single object +func (c GrafanaResourceClient) GrafanaListComplete(ctx context.Context, id commonids.SubscriptionId) (GrafanaListCompleteResult, error) { + return c.GrafanaListCompleteMatchingPredicate(ctx, id, ManagedGrafanaOperationPredicate{}) +} + +// GrafanaListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GrafanaResourceClient) GrafanaListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ManagedGrafanaOperationPredicate) (result GrafanaListCompleteResult, err error) { + items := make([]ManagedGrafana, 0) + + resp, err := c.GrafanaList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GrafanaListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalistbyresourcegroup.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalistbyresourcegroup.go new file mode 100644 index 00000000000..461b131a921 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanalistbyresourcegroup.go @@ -0,0 +1,106 @@ +package grafanaresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedGrafana +} + +type GrafanaListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedGrafana +} + +type GrafanaListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GrafanaListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GrafanaListByResourceGroup ... +func (c GrafanaResourceClient) GrafanaListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result GrafanaListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GrafanaListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Dashboard/grafana", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedGrafana `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GrafanaListByResourceGroupComplete retrieves all the results into a single object +func (c GrafanaResourceClient) GrafanaListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (GrafanaListByResourceGroupCompleteResult, error) { + return c.GrafanaListByResourceGroupCompleteMatchingPredicate(ctx, id, ManagedGrafanaOperationPredicate{}) +} + +// GrafanaListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GrafanaResourceClient) GrafanaListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ManagedGrafanaOperationPredicate) (result GrafanaListByResourceGroupCompleteResult, err error) { + items := make([]ManagedGrafana, 0) + + resp, err := c.GrafanaListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GrafanaListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaupdate.go b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaupdate.go new file mode 100644 index 00000000000..e260315d6a2 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/method_grafanaupdate.go @@ -0,0 +1,58 @@ +package grafanaresource + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedGrafana +} + +// GrafanaUpdate ... +func (c GrafanaResourceClient) GrafanaUpdate(ctx context.Context, id GrafanaId, input ManagedGrafanaUpdateParameters) (result GrafanaUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedGrafana + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_azuremonitorworkspaceintegration.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_azuremonitorworkspaceintegration.go new file mode 100644 index 00000000000..8136257d950 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_azuremonitorworkspaceintegration.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureMonitorWorkspaceIntegration struct { + AzureMonitorWorkspaceResourceId *string `json:"azureMonitorWorkspaceResourceId,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterpriseconfigurations.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterpriseconfigurations.go new file mode 100644 index 00000000000..ac815a7ba02 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterpriseconfigurations.go @@ -0,0 +1,9 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnterpriseConfigurations struct { + MarketplaceAutoRenew *MarketplaceAutoRenew `json:"marketplaceAutoRenew,omitempty"` + MarketplacePlanId *string `json:"marketplacePlanId,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterprisedetails.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterprisedetails.go new file mode 100644 index 00000000000..34b5af46881 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_enterprisedetails.go @@ -0,0 +1,9 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnterpriseDetails struct { + MarketplaceTrialQuota *MarketplaceTrialQuota `json:"marketplaceTrialQuota,omitempty"` + SaasSubscriptionDetails *SaasSubscriptionDetails `json:"saasSubscriptionDetails,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaconfigurations.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaconfigurations.go new file mode 100644 index 00000000000..f8919be5101 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaconfigurations.go @@ -0,0 +1,11 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaConfigurations struct { + Security *Security `json:"security,omitempty"` + Smtp *Smtp `json:"smtp,omitempty"` + Snapshots *Snapshots `json:"snapshots,omitempty"` + Users *Users `json:"users,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaintegrations.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaintegrations.go new file mode 100644 index 00000000000..80a683ba946 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaintegrations.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaIntegrations struct { + AzureMonitorWorkspaceIntegrations *[]AzureMonitorWorkspaceIntegration `json:"azureMonitorWorkspaceIntegrations,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaplugin.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaplugin.go new file mode 100644 index 00000000000..70d063d7e13 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_grafanaplugin.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrafanaPlugin struct { + PluginId *string `json:"pluginId,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafana.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafana.go new file mode 100644 index 00000000000..a4866e11e9d --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafana.go @@ -0,0 +1,21 @@ +package grafanaresource + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedGrafana struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedGrafanaProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaproperties.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaproperties.go new file mode 100644 index 00000000000..e375da2f83e --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaproperties.go @@ -0,0 +1,22 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedGrafanaProperties struct { + ApiKey *ApiKey `json:"apiKey,omitempty"` + AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope `json:"autoGeneratedDomainNameLabelScope,omitempty"` + DeterministicOutboundIP *DeterministicOutboundIP `json:"deterministicOutboundIP,omitempty"` + Endpoint *string `json:"endpoint,omitempty"` + EnterpriseConfigurations *EnterpriseConfigurations `json:"enterpriseConfigurations,omitempty"` + GrafanaConfigurations *GrafanaConfigurations `json:"grafanaConfigurations,omitempty"` + GrafanaIntegrations *GrafanaIntegrations `json:"grafanaIntegrations,omitempty"` + GrafanaMajorVersion *string `json:"grafanaMajorVersion,omitempty"` + GrafanaPlugins *map[string]GrafanaPlugin `json:"grafanaPlugins,omitempty"` + GrafanaVersion *string `json:"grafanaVersion,omitempty"` + OutboundIPs *[]string `json:"outboundIPs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ZoneRedundancy *ZoneRedundancy `json:"zoneRedundancy,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanapropertiesupdateparameters.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanapropertiesupdateparameters.go new file mode 100644 index 00000000000..ae8577dea1c --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanapropertiesupdateparameters.go @@ -0,0 +1,16 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedGrafanaPropertiesUpdateParameters struct { + ApiKey *ApiKey `json:"apiKey,omitempty"` + DeterministicOutboundIP *DeterministicOutboundIP `json:"deterministicOutboundIP,omitempty"` + EnterpriseConfigurations *EnterpriseConfigurations `json:"enterpriseConfigurations,omitempty"` + GrafanaConfigurations *GrafanaConfigurations `json:"grafanaConfigurations,omitempty"` + GrafanaIntegrations *GrafanaIntegrations `json:"grafanaIntegrations,omitempty"` + GrafanaMajorVersion *string `json:"grafanaMajorVersion,omitempty"` + GrafanaPlugins *map[string]GrafanaPlugin `json:"grafanaPlugins,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ZoneRedundancy *ZoneRedundancy `json:"zoneRedundancy,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaupdateparameters.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaupdateparameters.go new file mode 100644 index 00000000000..ac2f495599b --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_managedgrafanaupdateparameters.go @@ -0,0 +1,15 @@ +package grafanaresource + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedGrafanaUpdateParameters struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ManagedGrafanaPropertiesUpdateParameters `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_marketplacetrialquota.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_marketplacetrialquota.go new file mode 100644 index 00000000000..bad9e3bba2d --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_marketplacetrialquota.go @@ -0,0 +1,41 @@ +package grafanaresource + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MarketplaceTrialQuota struct { + AvailablePromotion *AvailablePromotion `json:"availablePromotion,omitempty"` + GrafanaResourceId *string `json:"grafanaResourceId,omitempty"` + TrialEndAt *string `json:"trialEndAt,omitempty"` + TrialStartAt *string `json:"trialStartAt,omitempty"` +} + +func (o *MarketplaceTrialQuota) GetTrialEndAtAsTime() (*time.Time, error) { + if o.TrialEndAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TrialEndAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MarketplaceTrialQuota) SetTrialEndAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TrialEndAt = &formatted +} + +func (o *MarketplaceTrialQuota) GetTrialStartAtAsTime() (*time.Time, error) { + if o.TrialStartAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TrialStartAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MarketplaceTrialQuota) SetTrialStartAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TrialStartAt = &formatted +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpoint.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpoint.go new file mode 100644 index 00000000000..10e98b0bb2f --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpoint.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnection.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnection.go new file mode 100644 index 00000000000..fd33336690f --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package grafanaresource + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnectionproperties.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..68afbda6939 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_privatelinkserviceconnectionstate.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..d61484a0166 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_resourcesku.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_resourcesku.go new file mode 100644 index 00000000000..96839106d85 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_resourcesku.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSku struct { + Name string `json:"name"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_saassubscriptiondetails.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_saassubscriptiondetails.go new file mode 100644 index 00000000000..92519a99eef --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_saassubscriptiondetails.go @@ -0,0 +1,11 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SaasSubscriptionDetails struct { + OfferId *string `json:"offerId,omitempty"` + PlanId *string `json:"planId,omitempty"` + PublisherId *string `json:"publisherId,omitempty"` + Term *SubscriptionTerm `json:"term,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_security.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_security.go new file mode 100644 index 00000000000..0cca02620de --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_security.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Security struct { + CsrfAlwaysCheck *bool `json:"csrfAlwaysCheck,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_smtp.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_smtp.go new file mode 100644 index 00000000000..d2916ff8670 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_smtp.go @@ -0,0 +1,15 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Smtp struct { + Enabled *bool `json:"enabled,omitempty"` + FromAddress *string `json:"fromAddress,omitempty"` + FromName *string `json:"fromName,omitempty"` + Host *string `json:"host,omitempty"` + Password *string `json:"password,omitempty"` + SkipVerify *bool `json:"skipVerify,omitempty"` + StartTLSPolicy *StartTLSPolicy `json:"startTLSPolicy,omitempty"` + User *string `json:"user,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_snapshots.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_snapshots.go new file mode 100644 index 00000000000..8bd37d57c12 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_snapshots.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Snapshots struct { + ExternalEnabled *bool `json:"externalEnabled,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_subscriptionterm.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_subscriptionterm.go new file mode 100644 index 00000000000..7d674fbc018 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_subscriptionterm.go @@ -0,0 +1,40 @@ +package grafanaresource + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionTerm struct { + EndDate *string `json:"endDate,omitempty"` + StartDate *string `json:"startDate,omitempty"` + TermUnit *string `json:"termUnit,omitempty"` +} + +func (o *SubscriptionTerm) GetEndDateAsTime() (*time.Time, error) { + if o.EndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionTerm) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = &formatted +} + +func (o *SubscriptionTerm) GetStartDateAsTime() (*time.Time, error) { + if o.StartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionTerm) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = &formatted +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/model_users.go b/resource-manager/dashboard/2024-10-01/grafanaresource/model_users.go new file mode 100644 index 00000000000..7ddf115696e --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/model_users.go @@ -0,0 +1,8 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Users struct { + ViewersCanEdit *bool `json:"viewersCanEdit,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/predicates.go b/resource-manager/dashboard/2024-10-01/grafanaresource/predicates.go new file mode 100644 index 00000000000..c49bf210e5a --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/predicates.go @@ -0,0 +1,32 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedGrafanaOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedGrafanaOperationPredicate) Matches(input ManagedGrafana) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/grafanaresource/version.go b/resource-manager/dashboard/2024-10-01/grafanaresource/version.go new file mode 100644 index 00000000000..4f1485993ab --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/grafanaresource/version.go @@ -0,0 +1,10 @@ +package grafanaresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/grafanaresource/2024-10-01" +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/README.md b/resource-manager/dashboard/2024-10-01/integrationfabric/README.md new file mode 100644 index 00000000000..8001936b659 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/integrationfabric` Documentation + +The `integrationfabric` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/integrationfabric" +``` + + +### Client Initialization + +```go +client := integrationfabric.NewIntegrationFabricClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IntegrationFabricClient.Create` + +```go +ctx := context.TODO() +id := integrationfabric.NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName") + +payload := integrationfabric.IntegrationFabric{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationFabricClient.Delete` + +```go +ctx := context.TODO() +id := integrationfabric.NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationFabricClient.Get` + +```go +ctx := context.TODO() +id := integrationfabric.NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationFabricClient.List` + +```go +ctx := context.TODO() +id := integrationfabric.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `IntegrationFabricClient.Update` + +```go +ctx := context.TODO() +id := integrationfabric.NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName") + +payload := integrationfabric.IntegrationFabricUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/client.go b/resource-manager/dashboard/2024-10-01/integrationfabric/client.go new file mode 100644 index 00000000000..b7854b3d1a2 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/client.go @@ -0,0 +1,26 @@ +package integrationfabric + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabricClient struct { + Client *resourcemanager.Client +} + +func NewIntegrationFabricClientWithBaseURI(sdkApi sdkEnv.Api) (*IntegrationFabricClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "integrationfabric", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IntegrationFabricClient: %+v", err) + } + + return &IntegrationFabricClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/constants.go b/resource-manager/dashboard/2024-10-01/integrationfabric/constants.go new file mode 100644 index 00000000000..35fcd837fc8 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/constants.go @@ -0,0 +1,72 @@ +package integrationfabric + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana.go b/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana.go new file mode 100644 index 00000000000..088e4d2752c --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana.go @@ -0,0 +1,130 @@ +package integrationfabric + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana_test.go new file mode 100644 index 00000000000..a199022b541 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/id_grafana_test.go @@ -0,0 +1,282 @@ +package integrationfabric + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric.go b/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric.go new file mode 100644 index 00000000000..55ad67d2144 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric.go @@ -0,0 +1,139 @@ +package integrationfabric + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IntegrationFabricId{}) +} + +var _ resourceids.ResourceId = &IntegrationFabricId{} + +// IntegrationFabricId is a struct representing the Resource ID for a Integration Fabric +type IntegrationFabricId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + IntegrationFabricName string +} + +// NewIntegrationFabricID returns a new IntegrationFabricId struct +func NewIntegrationFabricID(subscriptionId string, resourceGroupName string, grafanaName string, integrationFabricName string) IntegrationFabricId { + return IntegrationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + IntegrationFabricName: integrationFabricName, + } +} + +// ParseIntegrationFabricID parses 'input' into a IntegrationFabricId +func ParseIntegrationFabricID(input string) (*IntegrationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationFabricId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIntegrationFabricIDInsensitively parses 'input' case-insensitively into a IntegrationFabricId +// note: this method should only be used for API response data and not user input +func ParseIntegrationFabricIDInsensitively(input string) (*IntegrationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationFabricId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IntegrationFabricId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + if id.IntegrationFabricName, ok = input.Parsed["integrationFabricName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "integrationFabricName", input) + } + + return nil +} + +// ValidateIntegrationFabricID checks that 'input' can be parsed as a Integration Fabric ID +func ValidateIntegrationFabricID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIntegrationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Integration Fabric ID +func (id IntegrationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s/integrationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName, id.IntegrationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Integration Fabric ID +func (id IntegrationFabricId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + resourceids.StaticSegment("staticIntegrationFabrics", "integrationFabrics", "integrationFabrics"), + resourceids.UserSpecifiedSegment("integrationFabricName", "integrationFabricName"), + } +} + +// String returns a human-readable description of this Integration Fabric ID +func (id IntegrationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + fmt.Sprintf("Integration Fabric Name: %q", id.IntegrationFabricName), + } + return fmt.Sprintf("Integration Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric_test.go b/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric_test.go new file mode 100644 index 00000000000..7e9b12121d8 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/id_integrationfabric_test.go @@ -0,0 +1,327 @@ +package integrationfabric + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IntegrationFabricId{} + +func TestNewIntegrationFabricID(t *testing.T) { + id := NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } + + if id.IntegrationFabricName != "integrationFabricName" { + t.Fatalf("Expected %q but got %q for Segment 'IntegrationFabricName'", id.IntegrationFabricName, "integrationFabricName") + } +} + +func TestFormatIntegrationFabricID(t *testing.T) { + actual := NewIntegrationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "integrationFabricName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics/integrationFabricName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIntegrationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationFabricId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics/integrationFabricName", + Expected: &IntegrationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + IntegrationFabricName: "integrationFabricName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics/integrationFabricName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationFabricID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.IntegrationFabricName != v.Expected.IntegrationFabricName { + t.Fatalf("Expected %q but got %q for IntegrationFabricName", v.Expected.IntegrationFabricName, actual.IntegrationFabricName) + } + + } +} + +func TestParseIntegrationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationFabricId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/iNtEgRaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics/integrationFabricName", + Expected: &IntegrationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + IntegrationFabricName: "integrationFabricName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/integrationFabrics/integrationFabricName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/iNtEgRaTiOnFaBrIcS/iNtEgRaTiOnFaBrIcNaMe", + Expected: &IntegrationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + IntegrationFabricName: "iNtEgRaTiOnFaBrIcNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/iNtEgRaTiOnFaBrIcS/iNtEgRaTiOnFaBrIcNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationFabricIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.IntegrationFabricName != v.Expected.IntegrationFabricName { + t.Fatalf("Expected %q but got %q for IntegrationFabricName", v.Expected.IntegrationFabricName, actual.IntegrationFabricName) + } + + } +} + +func TestSegmentsForIntegrationFabricId(t *testing.T) { + segments := IntegrationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IntegrationFabricId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/method_create.go b/resource-manager/dashboard/2024-10-01/integrationfabric/method_create.go new file mode 100644 index 00000000000..a7027c2ae54 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/method_create.go @@ -0,0 +1,75 @@ +package integrationfabric + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationFabric +} + +// Create ... +func (c IntegrationFabricClient) Create(ctx context.Context, id IntegrationFabricId, input IntegrationFabric) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c IntegrationFabricClient) CreateThenPoll(ctx context.Context, id IntegrationFabricId, input IntegrationFabric) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/method_delete.go b/resource-manager/dashboard/2024-10-01/integrationfabric/method_delete.go new file mode 100644 index 00000000000..2126c4a0543 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/method_delete.go @@ -0,0 +1,70 @@ +package integrationfabric + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IntegrationFabricClient) Delete(ctx context.Context, id IntegrationFabricId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c IntegrationFabricClient) DeleteThenPoll(ctx context.Context, id IntegrationFabricId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/method_get.go b/resource-manager/dashboard/2024-10-01/integrationfabric/method_get.go new file mode 100644 index 00000000000..979fbe731de --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/method_get.go @@ -0,0 +1,53 @@ +package integrationfabric + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationFabric +} + +// Get ... +func (c IntegrationFabricClient) Get(ctx context.Context, id IntegrationFabricId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model IntegrationFabric + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/method_list.go b/resource-manager/dashboard/2024-10-01/integrationfabric/method_list.go new file mode 100644 index 00000000000..66e80cfb47b --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/method_list.go @@ -0,0 +1,105 @@ +package integrationfabric + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IntegrationFabric +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IntegrationFabric +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c IntegrationFabricClient) List(ctx context.Context, id GrafanaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/integrationFabrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IntegrationFabric `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c IntegrationFabricClient) ListComplete(ctx context.Context, id GrafanaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, IntegrationFabricOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IntegrationFabricClient) ListCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate IntegrationFabricOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IntegrationFabric, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/method_update.go b/resource-manager/dashboard/2024-10-01/integrationfabric/method_update.go new file mode 100644 index 00000000000..1015c6d1df1 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/method_update.go @@ -0,0 +1,75 @@ +package integrationfabric + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationFabric +} + +// Update ... +func (c IntegrationFabricClient) Update(ctx context.Context, id IntegrationFabricId, input IntegrationFabricUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c IntegrationFabricClient) UpdateThenPoll(ctx context.Context, id IntegrationFabricId, input IntegrationFabricUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabric.go b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabric.go new file mode 100644 index 00000000000..c2c7469e8e5 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabric.go @@ -0,0 +1,18 @@ +package integrationfabric + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabric struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *IntegrationFabricProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricproperties.go b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricproperties.go new file mode 100644 index 00000000000..58c464e49ae --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricproperties.go @@ -0,0 +1,11 @@ +package integrationfabric + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabricProperties struct { + DataSourceResourceId *string `json:"dataSourceResourceId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Scenarios *[]string `json:"scenarios,omitempty"` + TargetResourceId *string `json:"targetResourceId,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricpropertiesupdateparameters.go b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricpropertiesupdateparameters.go new file mode 100644 index 00000000000..32555689f23 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricpropertiesupdateparameters.go @@ -0,0 +1,8 @@ +package integrationfabric + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabricPropertiesUpdateParameters struct { + Scenarios *[]string `json:"scenarios,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricupdateparameters.go b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricupdateparameters.go new file mode 100644 index 00000000000..d943b839b2d --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/model_integrationfabricupdateparameters.go @@ -0,0 +1,9 @@ +package integrationfabric + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabricUpdateParameters struct { + Properties *IntegrationFabricPropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/predicates.go b/resource-manager/dashboard/2024-10-01/integrationfabric/predicates.go new file mode 100644 index 00000000000..e7508987e41 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/predicates.go @@ -0,0 +1,32 @@ +package integrationfabric + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationFabricOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p IntegrationFabricOperationPredicate) Matches(input IntegrationFabric) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/integrationfabric/version.go b/resource-manager/dashboard/2024-10-01/integrationfabric/version.go new file mode 100644 index 00000000000..36c313d4582 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/integrationfabric/version.go @@ -0,0 +1,10 @@ +package integrationfabric + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/integrationfabric/2024-10-01" +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/README.md b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/README.md new file mode 100644 index 00000000000..dedc12b5667 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/managedprivateendpoints` Documentation + +The `managedprivateendpoints` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/managedprivateendpoints" +``` + + +### Client Initialization + +```go +client := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Create` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +payload := managedprivateendpoints.ManagedPrivateEndpointModel{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Delete` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Get` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.List` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Refresh` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +if err := client.RefreshThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedPrivateEndpointsClient.Update` + +```go +ctx := context.TODO() +id := managedprivateendpoints.NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + +payload := managedprivateendpoints.ManagedPrivateEndpointUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/client.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/client.go new file mode 100644 index 00000000000..e02237558e4 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/client.go @@ -0,0 +1,26 @@ +package managedprivateendpoints + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointsClient struct { + Client *resourcemanager.Client +} + +func NewManagedPrivateEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedPrivateEndpointsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedprivateendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedPrivateEndpointsClient: %+v", err) + } + + return &ManagedPrivateEndpointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/constants.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/constants.go new file mode 100644 index 00000000000..b9d6b033782 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/constants.go @@ -0,0 +1,119 @@ +package managedprivateendpoints + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointConnectionStatus string + +const ( + ManagedPrivateEndpointConnectionStatusApproved ManagedPrivateEndpointConnectionStatus = "Approved" + ManagedPrivateEndpointConnectionStatusDisconnected ManagedPrivateEndpointConnectionStatus = "Disconnected" + ManagedPrivateEndpointConnectionStatusPending ManagedPrivateEndpointConnectionStatus = "Pending" + ManagedPrivateEndpointConnectionStatusRejected ManagedPrivateEndpointConnectionStatus = "Rejected" +) + +func PossibleValuesForManagedPrivateEndpointConnectionStatus() []string { + return []string{ + string(ManagedPrivateEndpointConnectionStatusApproved), + string(ManagedPrivateEndpointConnectionStatusDisconnected), + string(ManagedPrivateEndpointConnectionStatusPending), + string(ManagedPrivateEndpointConnectionStatusRejected), + } +} + +func (s *ManagedPrivateEndpointConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedPrivateEndpointConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedPrivateEndpointConnectionStatus(input string) (*ManagedPrivateEndpointConnectionStatus, error) { + vals := map[string]ManagedPrivateEndpointConnectionStatus{ + "approved": ManagedPrivateEndpointConnectionStatusApproved, + "disconnected": ManagedPrivateEndpointConnectionStatusDisconnected, + "pending": ManagedPrivateEndpointConnectionStatusPending, + "rejected": ManagedPrivateEndpointConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedPrivateEndpointConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana.go new file mode 100644 index 00000000000..2a7fb9d4c02 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana.go @@ -0,0 +1,130 @@ +package managedprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana_test.go new file mode 100644 index 00000000000..b1dd43ffab9 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_grafana_test.go @@ -0,0 +1,282 @@ +package managedprivateendpoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint.go new file mode 100644 index 00000000000..f62eda38b79 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint.go @@ -0,0 +1,139 @@ +package managedprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedPrivateEndpointId{}) +} + +var _ resourceids.ResourceId = &ManagedPrivateEndpointId{} + +// ManagedPrivateEndpointId is a struct representing the Resource ID for a Managed Private Endpoint +type ManagedPrivateEndpointId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + ManagedPrivateEndpointName string +} + +// NewManagedPrivateEndpointID returns a new ManagedPrivateEndpointId struct +func NewManagedPrivateEndpointID(subscriptionId string, resourceGroupName string, grafanaName string, managedPrivateEndpointName string) ManagedPrivateEndpointId { + return ManagedPrivateEndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + ManagedPrivateEndpointName: managedPrivateEndpointName, + } +} + +// ParseManagedPrivateEndpointID parses 'input' into a ManagedPrivateEndpointId +func ParseManagedPrivateEndpointID(input string) (*ManagedPrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedPrivateEndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedPrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedPrivateEndpointIDInsensitively parses 'input' case-insensitively into a ManagedPrivateEndpointId +// note: this method should only be used for API response data and not user input +func ParseManagedPrivateEndpointIDInsensitively(input string) (*ManagedPrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedPrivateEndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedPrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedPrivateEndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + if id.ManagedPrivateEndpointName, ok = input.Parsed["managedPrivateEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedPrivateEndpointName", input) + } + + return nil +} + +// ValidateManagedPrivateEndpointID checks that 'input' can be parsed as a Managed Private Endpoint ID +func ValidateManagedPrivateEndpointID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedPrivateEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s/managedPrivateEndpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName, id.ManagedPrivateEndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + resourceids.StaticSegment("staticManagedPrivateEndpoints", "managedPrivateEndpoints", "managedPrivateEndpoints"), + resourceids.UserSpecifiedSegment("managedPrivateEndpointName", "managedPrivateEndpointName"), + } +} + +// String returns a human-readable description of this Managed Private Endpoint ID +func (id ManagedPrivateEndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + fmt.Sprintf("Managed Private Endpoint Name: %q", id.ManagedPrivateEndpointName), + } + return fmt.Sprintf("Managed Private Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint_test.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint_test.go new file mode 100644 index 00000000000..df907e9393c --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/id_managedprivateendpoint_test.go @@ -0,0 +1,327 @@ +package managedprivateendpoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedPrivateEndpointId{} + +func TestNewManagedPrivateEndpointID(t *testing.T) { + id := NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } + + if id.ManagedPrivateEndpointName != "managedPrivateEndpointName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedPrivateEndpointName'", id.ManagedPrivateEndpointName, "managedPrivateEndpointName") + } +} + +func TestFormatManagedPrivateEndpointID(t *testing.T) { + actual := NewManagedPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "managedPrivateEndpointName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints/managedPrivateEndpointName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedPrivateEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedPrivateEndpointId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints/managedPrivateEndpointName", + Expected: &ManagedPrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + ManagedPrivateEndpointName: "managedPrivateEndpointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints/managedPrivateEndpointName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedPrivateEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.ManagedPrivateEndpointName != v.Expected.ManagedPrivateEndpointName { + t.Fatalf("Expected %q but got %q for ManagedPrivateEndpointName", v.Expected.ManagedPrivateEndpointName, actual.ManagedPrivateEndpointName) + } + + } +} + +func TestParseManagedPrivateEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedPrivateEndpointId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/mAnAgEdPrIvAtEeNdPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints/managedPrivateEndpointName", + Expected: &ManagedPrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + ManagedPrivateEndpointName: "managedPrivateEndpointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/managedPrivateEndpoints/managedPrivateEndpointName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/mAnAgEdPrIvAtEeNdPoInTs/mAnAgEdPrIvAtEeNdPoInTnAmE", + Expected: &ManagedPrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + ManagedPrivateEndpointName: "mAnAgEdPrIvAtEeNdPoInTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/mAnAgEdPrIvAtEeNdPoInTs/mAnAgEdPrIvAtEeNdPoInTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedPrivateEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.ManagedPrivateEndpointName != v.Expected.ManagedPrivateEndpointName { + t.Fatalf("Expected %q but got %q for ManagedPrivateEndpointName", v.Expected.ManagedPrivateEndpointName, actual.ManagedPrivateEndpointName) + } + + } +} + +func TestSegmentsForManagedPrivateEndpointId(t *testing.T) { + segments := ManagedPrivateEndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedPrivateEndpointId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_create.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_create.go new file mode 100644 index 00000000000..47504c5921d --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_create.go @@ -0,0 +1,75 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedPrivateEndpointModel +} + +// Create ... +func (c ManagedPrivateEndpointsClient) Create(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointModel) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ManagedPrivateEndpointsClient) CreateThenPoll(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointModel) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_delete.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_delete.go new file mode 100644 index 00000000000..98a0990b10a --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_delete.go @@ -0,0 +1,71 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedPrivateEndpointsClient) Delete(ctx context.Context, id ManagedPrivateEndpointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ManagedPrivateEndpointsClient) DeleteThenPoll(ctx context.Context, id ManagedPrivateEndpointId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_get.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_get.go new file mode 100644 index 00000000000..6840e6b4592 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_get.go @@ -0,0 +1,53 @@ +package managedprivateendpoints + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedPrivateEndpointModel +} + +// Get ... +func (c ManagedPrivateEndpointsClient) Get(ctx context.Context, id ManagedPrivateEndpointId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedPrivateEndpointModel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_list.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_list.go new file mode 100644 index 00000000000..4c9b506e1da --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_list.go @@ -0,0 +1,105 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedPrivateEndpointModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedPrivateEndpointModel +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ManagedPrivateEndpointsClient) List(ctx context.Context, id GrafanaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/managedPrivateEndpoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedPrivateEndpointModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ManagedPrivateEndpointsClient) ListComplete(ctx context.Context, id GrafanaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ManagedPrivateEndpointModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedPrivateEndpointsClient) ListCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate ManagedPrivateEndpointModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ManagedPrivateEndpointModel, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_refresh.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_refresh.go new file mode 100644 index 00000000000..fb9fec3c6d9 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_refresh.go @@ -0,0 +1,70 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Refresh ... +func (c ManagedPrivateEndpointsClient) Refresh(ctx context.Context, id GrafanaId) (result RefreshOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshManagedPrivateEndpoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RefreshThenPoll performs Refresh then polls until it's completed +func (c ManagedPrivateEndpointsClient) RefreshThenPoll(ctx context.Context, id GrafanaId) error { + result, err := c.Refresh(ctx, id) + if err != nil { + return fmt.Errorf("performing Refresh: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Refresh: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_update.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_update.go new file mode 100644 index 00000000000..6bfa37db056 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/method_update.go @@ -0,0 +1,75 @@ +package managedprivateendpoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedPrivateEndpointModel +} + +// Update ... +func (c ManagedPrivateEndpointsClient) Update(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ManagedPrivateEndpointsClient) UpdateThenPoll(ctx context.Context, id ManagedPrivateEndpointId, input ManagedPrivateEndpointUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go new file mode 100644 index 00000000000..a24ead5087a --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointconnectionstate.go @@ -0,0 +1,9 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointConnectionState struct { + Description *string `json:"description,omitempty"` + Status *ManagedPrivateEndpointConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodel.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodel.go new file mode 100644 index 00000000000..109bc1c4e6e --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodel.go @@ -0,0 +1,18 @@ +package managedprivateendpoints + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModel struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedPrivateEndpointModelProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go new file mode 100644 index 00000000000..babce0bcb68 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointmodelproperties.go @@ -0,0 +1,15 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModelProperties struct { + ConnectionState *ManagedPrivateEndpointConnectionState `json:"connectionState,omitempty"` + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateLinkResourceId *string `json:"privateLinkResourceId,omitempty"` + PrivateLinkResourceRegion *string `json:"privateLinkResourceRegion,omitempty"` + PrivateLinkServicePrivateIP *string `json:"privateLinkServicePrivateIP,omitempty"` + PrivateLinkServiceURL *string `json:"privateLinkServiceUrl,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequestMessage *string `json:"requestMessage,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go new file mode 100644 index 00000000000..f7322b80184 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/model_managedprivateendpointupdateparameters.go @@ -0,0 +1,8 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointUpdateParameters struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/predicates.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/predicates.go new file mode 100644 index 00000000000..108b63e5f74 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/predicates.go @@ -0,0 +1,32 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedPrivateEndpointModelOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedPrivateEndpointModelOperationPredicate) Matches(input ManagedPrivateEndpointModel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/managedprivateendpoints/version.go b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/version.go new file mode 100644 index 00000000000..5418b21fed8 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/managedprivateendpoints/version.go @@ -0,0 +1,10 @@ +package managedprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedprivateendpoints/2024-10-01" +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/README.md b/resource-manager/dashboard/2024-10-01/privateendpointconnection/README.md new file mode 100644 index 00000000000..67023495bec --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privateendpointconnection` Documentation + +The `privateendpointconnection` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privateendpointconnection" +``` + + +### Client Initialization + +```go +client := privateendpointconnection.NewPrivateEndpointConnectionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionClient.Approve` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateEndpointConnectionName") + +payload := privateendpointconnection.PrivateEndpointConnection{ + // ... +} + + +if err := client.ApproveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/client.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/client.go new file mode 100644 index 00000000000..60f4edcfcfb --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/client.go @@ -0,0 +1,26 @@ +package privateendpointconnection + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnection", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionClient: %+v", err) + } + + return &PrivateEndpointConnectionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/constants.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/constants.go new file mode 100644 index 00000000000..eea4dc86b53 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnection + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana.go new file mode 100644 index 00000000000..5dbf3ad1135 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana.go @@ -0,0 +1,130 @@ +package privateendpointconnection + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana_test.go new file mode 100644 index 00000000000..8d7b15766a9 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_grafana_test.go @@ -0,0 +1,282 @@ +package privateendpointconnection + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection.go new file mode 100644 index 00000000000..482d0d491b5 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnection + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, grafanaName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection_test.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..b043bff6455 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnection + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_approve.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_approve.go new file mode 100644 index 00000000000..235488e890c --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_approve.go @@ -0,0 +1,74 @@ +package privateendpointconnection + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApproveOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Approve ... +func (c PrivateEndpointConnectionClient) Approve(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result ApproveOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ApproveThenPoll performs Approve then polls until it's completed +func (c PrivateEndpointConnectionClient) ApproveThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.Approve(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Approve: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Approve: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_delete.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_delete.go new file mode 100644 index 00000000000..79b75c96d92 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_delete.go @@ -0,0 +1,70 @@ +package privateendpointconnection + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateEndpointConnectionClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_get.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_get.go new file mode 100644 index 00000000000..0658c39bfa5 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnection + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_list.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_list.go new file mode 100644 index 00000000000..991344dbaf5 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/method_list.go @@ -0,0 +1,105 @@ +package privateendpointconnection + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PrivateEndpointConnectionClient) List(ctx context.Context, id GrafanaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionClient) ListComplete(ctx context.Context, id GrafanaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionClient) ListCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate PrivateEndpointConnectionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpoint.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpoint.go new file mode 100644 index 00000000000..36d044c72d1 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnection.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnection.go new file mode 100644 index 00000000000..348b71b8bf6 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package privateendpointconnection + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnectionproperties.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..3fd1295eb9e --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..a2b2ae6d7d3 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/predicates.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/predicates.go new file mode 100644 index 00000000000..ed0e5025416 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/predicates.go @@ -0,0 +1,27 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/privateendpointconnection/version.go b/resource-manager/dashboard/2024-10-01/privateendpointconnection/version.go new file mode 100644 index 00000000000..b8a74afce5b --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privateendpointconnection/version.go @@ -0,0 +1,10 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnection/2024-10-01" +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/README.md b/resource-manager/dashboard/2024-10-01/privatelinkresource/README.md new file mode 100644 index 00000000000..812150b6b45 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privatelinkresource` Documentation + +The `privatelinkresource` SDK allows for interaction with Azure Resource Manager `dashboard` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2024-10-01/privatelinkresource" +``` + + +### Client Initialization + +```go +client := privatelinkresource.NewPrivateLinkResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourceClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresource.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateLinkResourceName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkResourceClient.List` + +```go +ctx := context.TODO() +id := privatelinkresource.NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/client.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/client.go new file mode 100644 index 00000000000..36c07ed6dbf --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/client.go @@ -0,0 +1,26 @@ +package privatelinkresource + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourceClient: %+v", err) + } + + return &PrivateLinkResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/constants.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/constants.go new file mode 100644 index 00000000000..d77f4ae4492 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/constants.go @@ -0,0 +1,72 @@ +package privatelinkresource + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana.go new file mode 100644 index 00000000000..0db525e40c5 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana.go @@ -0,0 +1,130 @@ +package privatelinkresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GrafanaId{}) +} + +var _ resourceids.ResourceId = &GrafanaId{} + +// GrafanaId is a struct representing the Resource ID for a Grafana +type GrafanaId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string +} + +// NewGrafanaID returns a new GrafanaId struct +func NewGrafanaID(subscriptionId string, resourceGroupName string, grafanaName string) GrafanaId { + return GrafanaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + } +} + +// ParseGrafanaID parses 'input' into a GrafanaId +func ParseGrafanaID(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGrafanaIDInsensitively parses 'input' case-insensitively into a GrafanaId +// note: this method should only be used for API response data and not user input +func ParseGrafanaIDInsensitively(input string) (*GrafanaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GrafanaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GrafanaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GrafanaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + return nil +} + +// ValidateGrafanaID checks that 'input' can be parsed as a Grafana ID +func ValidateGrafanaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGrafanaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Grafana ID +func (id GrafanaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Grafana ID +func (id GrafanaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + } +} + +// String returns a human-readable description of this Grafana ID +func (id GrafanaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + } + return fmt.Sprintf("Grafana (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana_test.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana_test.go new file mode 100644 index 00000000000..e8feeb3f139 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_grafana_test.go @@ -0,0 +1,282 @@ +package privatelinkresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GrafanaId{} + +func TestNewGrafanaID(t *testing.T) { + id := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } +} + +func TestFormatGrafanaID(t *testing.T) { + actual := NewGrafanaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGrafanaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestParseGrafanaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GrafanaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Expected: &GrafanaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGrafanaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + } +} + +func TestSegmentsForGrafanaId(t *testing.T) { + segments := GrafanaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GrafanaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource.go new file mode 100644 index 00000000000..c87f8566bfb --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource.go @@ -0,0 +1,139 @@ +package privatelinkresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + GrafanaName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, grafanaName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GrafanaName: grafanaName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GrafanaName, ok = input.Parsed["grafanaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "grafanaName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Dashboard/grafana/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GrafanaName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDashboard", "Microsoft.Dashboard", "Microsoft.Dashboard"), + resourceids.StaticSegment("staticGrafana", "grafana", "grafana"), + resourceids.UserSpecifiedSegment("grafanaName", "grafanaName"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceName"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Grafana Name: %q", id.GrafanaName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource_test.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource_test.go new file mode 100644 index 00000000000..5d55b95c0bb --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateLinkResourceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GrafanaName != "grafanaName" { + t.Fatalf("Expected %q but got %q for Segment 'GrafanaName'", id.GrafanaName, "grafanaName") + } + + if id.PrivateLinkResourceName != "privateLinkResourceName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceName") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "grafanaName", "privateLinkResourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources/privateLinkResourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GrafanaName: "grafanaName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Dashboard/grafana/grafanaName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GrafanaName: "gRaFaNaNaMe", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAsHbOaRd/gRaFaNa/gRaFaNaNaMe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GrafanaName != v.Expected.GrafanaName { + t.Fatalf("Expected %q but got %q for GrafanaName", v.Expected.GrafanaName, actual.GrafanaName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/method_get.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/method_get.go new file mode 100644 index 00000000000..a408895b355 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/method_get.go @@ -0,0 +1,53 @@ +package privatelinkresource + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourceClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/method_list.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/method_list.go new file mode 100644 index 00000000000..898cb40d728 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/method_list.go @@ -0,0 +1,105 @@ +package privatelinkresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PrivateLinkResourceClient) List(ctx context.Context, id GrafanaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateLinkResourceClient) ListComplete(ctx context.Context, id GrafanaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkResourceClient) ListCompleteMatchingPredicate(ctx context.Context, id GrafanaId, predicate PrivateLinkResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresource.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresource.go new file mode 100644 index 00000000000..ad6f8c999da --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresource.go @@ -0,0 +1,16 @@ +package privatelinkresource + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresourceproperties.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..c1f86c15dd7 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/model_privatelinkresourceproperties.go @@ -0,0 +1,11 @@ +package privatelinkresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/predicates.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/predicates.go new file mode 100644 index 00000000000..3392e26881e --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/predicates.go @@ -0,0 +1,27 @@ +package privatelinkresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dashboard/2024-10-01/privatelinkresource/version.go b/resource-manager/dashboard/2024-10-01/privatelinkresource/version.go new file mode 100644 index 00000000000..d47eef74608 --- /dev/null +++ b/resource-manager/dashboard/2024-10-01/privatelinkresource/version.go @@ -0,0 +1,10 @@ +package privatelinkresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresource/2024-10-01" +} diff --git a/resource-manager/keyvault/2024-11-01/client.go b/resource-manager/keyvault/2024-11-01/client.go new file mode 100644 index 00000000000..b95f6cb540e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/client.go @@ -0,0 +1,118 @@ +package v2024_11_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/keys" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsmkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsms" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistregions" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/secrets" + "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/vaults" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + Keys *keys.KeysClient + MHSMListPrivateEndpointConnections *mhsmlistprivateendpointconnections.MHSMListPrivateEndpointConnectionsClient + MHSMListRegions *mhsmlistregions.MHSMListRegionsClient + MHSMPrivateEndpointConnections *mhsmprivateendpointconnections.MHSMPrivateEndpointConnectionsClient + MHSMPrivateLinkResources *mhsmprivatelinkresources.MHSMPrivateLinkResourcesClient + ManagedHsmKeys *managedhsmkeys.ManagedHsmKeysClient + ManagedHsms *managedhsms.ManagedHsmsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + Secrets *secrets.SecretsClient + Vaults *vaults.VaultsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + keysClient, err := keys.NewKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Keys client: %+v", err) + } + configureFunc(keysClient.Client) + + mHSMListPrivateEndpointConnectionsClient, err := mhsmlistprivateendpointconnections.NewMHSMListPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MHSMListPrivateEndpointConnections client: %+v", err) + } + configureFunc(mHSMListPrivateEndpointConnectionsClient.Client) + + mHSMListRegionsClient, err := mhsmlistregions.NewMHSMListRegionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MHSMListRegions client: %+v", err) + } + configureFunc(mHSMListRegionsClient.Client) + + mHSMPrivateEndpointConnectionsClient, err := mhsmprivateendpointconnections.NewMHSMPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MHSMPrivateEndpointConnections client: %+v", err) + } + configureFunc(mHSMPrivateEndpointConnectionsClient.Client) + + mHSMPrivateLinkResourcesClient, err := mhsmprivatelinkresources.NewMHSMPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MHSMPrivateLinkResources client: %+v", err) + } + configureFunc(mHSMPrivateLinkResourcesClient.Client) + + managedHsmKeysClient, err := managedhsmkeys.NewManagedHsmKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedHsmKeys client: %+v", err) + } + configureFunc(managedHsmKeysClient.Client) + + managedHsmsClient, err := managedhsms.NewManagedHsmsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedHsms client: %+v", err) + } + configureFunc(managedHsmsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + secretsClient, err := secrets.NewSecretsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Secrets client: %+v", err) + } + configureFunc(secretsClient.Client) + + vaultsClient, err := vaults.NewVaultsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Vaults client: %+v", err) + } + configureFunc(vaultsClient.Client) + + return &Client{ + Keys: keysClient, + MHSMListPrivateEndpointConnections: mHSMListPrivateEndpointConnectionsClient, + MHSMListRegions: mHSMListRegionsClient, + MHSMPrivateEndpointConnections: mHSMPrivateEndpointConnectionsClient, + MHSMPrivateLinkResources: mHSMPrivateLinkResourcesClient, + ManagedHsmKeys: managedHsmKeysClient, + ManagedHsms: managedHsmsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + Secrets: secretsClient, + Vaults: vaultsClient, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/keys/README.md b/resource-manager/keyvault/2024-11-01/keys/README.md new file mode 100644 index 00000000000..5a4ba348488 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/README.md @@ -0,0 +1,108 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/keys` Documentation + +The `keys` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/keys" +``` + + +### Client Initialization + +```go +client := keys.NewKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `KeysClient.CreateIfNotExist` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "keyName") + +payload := keys.KeyCreateParameters{ + // ... +} + + +read, err := client.CreateIfNotExist(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "keyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.GetVersion` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultKeyVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "keyName", "versionName") + +read, err := client.GetVersion(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.List` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `KeysClient.ListVersions` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "keyName") + +// alternatively `client.ListVersions(ctx, id)` can be used to do batched pagination +items, err := client.ListVersionsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/keyvault/2024-11-01/keys/client.go b/resource-manager/keyvault/2024-11-01/keys/client.go new file mode 100644 index 00000000000..36c97638e22 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/client.go @@ -0,0 +1,26 @@ +package keys + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeysClient struct { + Client *resourcemanager.Client +} + +func NewKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*KeysClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "keys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating KeysClient: %+v", err) + } + + return &KeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/keys/constants.go b/resource-manager/keyvault/2024-11-01/keys/constants.go new file mode 100644 index 00000000000..ff9cd332a69 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/constants.go @@ -0,0 +1,251 @@ +package keys + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletionRecoveryLevel string + +const ( + DeletionRecoveryLevelPurgeable DeletionRecoveryLevel = "Purgeable" + DeletionRecoveryLevelRecoverable DeletionRecoveryLevel = "Recoverable" + DeletionRecoveryLevelRecoverablePositiveProtectedSubscription DeletionRecoveryLevel = "Recoverable+ProtectedSubscription" + DeletionRecoveryLevelRecoverablePositivePurgeable DeletionRecoveryLevel = "Recoverable+Purgeable" +) + +func PossibleValuesForDeletionRecoveryLevel() []string { + return []string{ + string(DeletionRecoveryLevelPurgeable), + string(DeletionRecoveryLevelRecoverable), + string(DeletionRecoveryLevelRecoverablePositiveProtectedSubscription), + string(DeletionRecoveryLevelRecoverablePositivePurgeable), + } +} + +func (s *DeletionRecoveryLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeletionRecoveryLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeletionRecoveryLevel(input string) (*DeletionRecoveryLevel, error) { + vals := map[string]DeletionRecoveryLevel{ + "purgeable": DeletionRecoveryLevelPurgeable, + "recoverable": DeletionRecoveryLevelRecoverable, + "recoverable+protectedsubscription": DeletionRecoveryLevelRecoverablePositiveProtectedSubscription, + "recoverable+purgeable": DeletionRecoveryLevelRecoverablePositivePurgeable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeletionRecoveryLevel(input) + return &out, nil +} + +type JsonWebKeyCurveName string + +const ( + JsonWebKeyCurveNamePNegativeFiveTwoOne JsonWebKeyCurveName = "P-521" + JsonWebKeyCurveNamePNegativeThreeEightFour JsonWebKeyCurveName = "P-384" + JsonWebKeyCurveNamePNegativeTwoFiveSix JsonWebKeyCurveName = "P-256" + JsonWebKeyCurveNamePNegativeTwoFiveSixK JsonWebKeyCurveName = "P-256K" +) + +func PossibleValuesForJsonWebKeyCurveName() []string { + return []string{ + string(JsonWebKeyCurveNamePNegativeFiveTwoOne), + string(JsonWebKeyCurveNamePNegativeThreeEightFour), + string(JsonWebKeyCurveNamePNegativeTwoFiveSix), + string(JsonWebKeyCurveNamePNegativeTwoFiveSixK), + } +} + +func (s *JsonWebKeyCurveName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyCurveName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyCurveName(input string) (*JsonWebKeyCurveName, error) { + vals := map[string]JsonWebKeyCurveName{ + "p-521": JsonWebKeyCurveNamePNegativeFiveTwoOne, + "p-384": JsonWebKeyCurveNamePNegativeThreeEightFour, + "p-256": JsonWebKeyCurveNamePNegativeTwoFiveSix, + "p-256k": JsonWebKeyCurveNamePNegativeTwoFiveSixK, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyCurveName(input) + return &out, nil +} + +type JsonWebKeyOperation string + +const ( + JsonWebKeyOperationDecrypt JsonWebKeyOperation = "decrypt" + JsonWebKeyOperationEncrypt JsonWebKeyOperation = "encrypt" + JsonWebKeyOperationImport JsonWebKeyOperation = "import" + JsonWebKeyOperationRelease JsonWebKeyOperation = "release" + JsonWebKeyOperationSign JsonWebKeyOperation = "sign" + JsonWebKeyOperationUnwrapKey JsonWebKeyOperation = "unwrapKey" + JsonWebKeyOperationVerify JsonWebKeyOperation = "verify" + JsonWebKeyOperationWrapKey JsonWebKeyOperation = "wrapKey" +) + +func PossibleValuesForJsonWebKeyOperation() []string { + return []string{ + string(JsonWebKeyOperationDecrypt), + string(JsonWebKeyOperationEncrypt), + string(JsonWebKeyOperationImport), + string(JsonWebKeyOperationRelease), + string(JsonWebKeyOperationSign), + string(JsonWebKeyOperationUnwrapKey), + string(JsonWebKeyOperationVerify), + string(JsonWebKeyOperationWrapKey), + } +} + +func (s *JsonWebKeyOperation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyOperation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyOperation(input string) (*JsonWebKeyOperation, error) { + vals := map[string]JsonWebKeyOperation{ + "decrypt": JsonWebKeyOperationDecrypt, + "encrypt": JsonWebKeyOperationEncrypt, + "import": JsonWebKeyOperationImport, + "release": JsonWebKeyOperationRelease, + "sign": JsonWebKeyOperationSign, + "unwrapkey": JsonWebKeyOperationUnwrapKey, + "verify": JsonWebKeyOperationVerify, + "wrapkey": JsonWebKeyOperationWrapKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyOperation(input) + return &out, nil +} + +type JsonWebKeyType string + +const ( + JsonWebKeyTypeEC JsonWebKeyType = "EC" + JsonWebKeyTypeECNegativeHSM JsonWebKeyType = "EC-HSM" + JsonWebKeyTypeRSA JsonWebKeyType = "RSA" + JsonWebKeyTypeRSANegativeHSM JsonWebKeyType = "RSA-HSM" +) + +func PossibleValuesForJsonWebKeyType() []string { + return []string{ + string(JsonWebKeyTypeEC), + string(JsonWebKeyTypeECNegativeHSM), + string(JsonWebKeyTypeRSA), + string(JsonWebKeyTypeRSANegativeHSM), + } +} + +func (s *JsonWebKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyType(input string) (*JsonWebKeyType, error) { + vals := map[string]JsonWebKeyType{ + "ec": JsonWebKeyTypeEC, + "ec-hsm": JsonWebKeyTypeECNegativeHSM, + "rsa": JsonWebKeyTypeRSA, + "rsa-hsm": JsonWebKeyTypeRSANegativeHSM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyType(input) + return &out, nil +} + +type KeyRotationPolicyActionType string + +const ( + KeyRotationPolicyActionTypeNotify KeyRotationPolicyActionType = "notify" + KeyRotationPolicyActionTypeRotate KeyRotationPolicyActionType = "rotate" +) + +func PossibleValuesForKeyRotationPolicyActionType() []string { + return []string{ + string(KeyRotationPolicyActionTypeNotify), + string(KeyRotationPolicyActionTypeRotate), + } +} + +func (s *KeyRotationPolicyActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyRotationPolicyActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyRotationPolicyActionType(input string) (*KeyRotationPolicyActionType, error) { + vals := map[string]KeyRotationPolicyActionType{ + "notify": KeyRotationPolicyActionTypeNotify, + "rotate": KeyRotationPolicyActionTypeRotate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyRotationPolicyActionType(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/keys/method_createifnotexist.go b/resource-manager/keyvault/2024-11-01/keys/method_createifnotexist.go new file mode 100644 index 00000000000..7e8e1c64add --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/method_createifnotexist.go @@ -0,0 +1,58 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateIfNotExistOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// CreateIfNotExist ... +func (c KeysClient) CreateIfNotExist(ctx context.Context, id commonids.KeyVaultKeyId, input KeyCreateParameters) (result CreateIfNotExistOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Key + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/keys/method_get.go b/resource-manager/keyvault/2024-11-01/keys/method_get.go new file mode 100644 index 00000000000..512fa087b6c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/method_get.go @@ -0,0 +1,54 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// Get ... +func (c KeysClient) Get(ctx context.Context, id commonids.KeyVaultKeyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Key + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/keys/method_getversion.go b/resource-manager/keyvault/2024-11-01/keys/method_getversion.go new file mode 100644 index 00000000000..18995ab6157 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/method_getversion.go @@ -0,0 +1,54 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetVersionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// GetVersion ... +func (c KeysClient) GetVersion(ctx context.Context, id commonids.KeyVaultKeyVersionId) (result GetVersionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Key + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/keys/method_list.go b/resource-manager/keyvault/2024-11-01/keys/method_list.go new file mode 100644 index 00000000000..ccd7ed01000 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/method_list.go @@ -0,0 +1,106 @@ +package keys + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Key +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Key +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c KeysClient) List(ctx context.Context, id commonids.KeyVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/keys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Key `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c KeysClient) ListComplete(ctx context.Context, id commonids.KeyVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, KeyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c KeysClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.KeyVaultId, predicate KeyOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Key, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/keys/method_listversions.go b/resource-manager/keyvault/2024-11-01/keys/method_listversions.go new file mode 100644 index 00000000000..e1b713d0eac --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/method_listversions.go @@ -0,0 +1,106 @@ +package keys + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListVersionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Key +} + +type ListVersionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Key +} + +type ListVersionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListVersionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListVersions ... +func (c KeysClient) ListVersions(ctx context.Context, id commonids.KeyVaultKeyId) (result ListVersionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListVersionsCustomPager{}, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Key `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListVersionsComplete retrieves all the results into a single object +func (c KeysClient) ListVersionsComplete(ctx context.Context, id commonids.KeyVaultKeyId) (ListVersionsCompleteResult, error) { + return c.ListVersionsCompleteMatchingPredicate(ctx, id, KeyOperationPredicate{}) +} + +// ListVersionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c KeysClient) ListVersionsCompleteMatchingPredicate(ctx context.Context, id commonids.KeyVaultKeyId, predicate KeyOperationPredicate) (result ListVersionsCompleteResult, err error) { + items := make([]Key, 0) + + resp, err := c.ListVersions(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListVersionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_action.go b/resource-manager/keyvault/2024-11-01/keys/model_action.go new file mode 100644 index 00000000000..50250a0db9b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_action.go @@ -0,0 +1,8 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Action struct { + Type *KeyRotationPolicyActionType `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_key.go b/resource-manager/keyvault/2024-11-01/keys/model_key.go new file mode 100644 index 00000000000..60f6d4257d8 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_key.go @@ -0,0 +1,13 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Key struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties KeyProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_keyattributes.go b/resource-manager/keyvault/2024-11-01/keys/model_keyattributes.go new file mode 100644 index 00000000000..ba14a8921b0 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_keyattributes.go @@ -0,0 +1,14 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyAttributes struct { + Created *int64 `json:"created,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Exp *int64 `json:"exp,omitempty"` + Exportable *bool `json:"exportable,omitempty"` + Nbf *int64 `json:"nbf,omitempty"` + RecoveryLevel *DeletionRecoveryLevel `json:"recoveryLevel,omitempty"` + Updated *int64 `json:"updated,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_keycreateparameters.go b/resource-manager/keyvault/2024-11-01/keys/model_keycreateparameters.go new file mode 100644 index 00000000000..4ce00d53412 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_keycreateparameters.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyCreateParameters struct { + Properties KeyProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_keyproperties.go b/resource-manager/keyvault/2024-11-01/keys/model_keyproperties.go new file mode 100644 index 00000000000..e81a89b5f5f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_keyproperties.go @@ -0,0 +1,16 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyProperties struct { + Attributes *KeyAttributes `json:"attributes,omitempty"` + CurveName *JsonWebKeyCurveName `json:"curveName,omitempty"` + KeyOps *[]JsonWebKeyOperation `json:"keyOps,omitempty"` + KeySize *int64 `json:"keySize,omitempty"` + KeyUri *string `json:"keyUri,omitempty"` + KeyUriWithVersion *string `json:"keyUriWithVersion,omitempty"` + Kty *JsonWebKeyType `json:"kty,omitempty"` + ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` + RotationPolicy *RotationPolicy `json:"rotationPolicy,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_keyreleasepolicy.go b/resource-manager/keyvault/2024-11-01/keys/model_keyreleasepolicy.go new file mode 100644 index 00000000000..51a28ffb506 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_keyreleasepolicy.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyReleasePolicy struct { + ContentType *string `json:"contentType,omitempty"` + Data *string `json:"data,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_keyrotationpolicyattributes.go b/resource-manager/keyvault/2024-11-01/keys/model_keyrotationpolicyattributes.go new file mode 100644 index 00000000000..50254af460c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_keyrotationpolicyattributes.go @@ -0,0 +1,10 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyRotationPolicyAttributes struct { + Created *int64 `json:"created,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Updated *int64 `json:"updated,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_lifetimeaction.go b/resource-manager/keyvault/2024-11-01/keys/model_lifetimeaction.go new file mode 100644 index 00000000000..aafb6dd8a07 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_lifetimeaction.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LifetimeAction struct { + Action *Action `json:"action,omitempty"` + Trigger *Trigger `json:"trigger,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_rotationpolicy.go b/resource-manager/keyvault/2024-11-01/keys/model_rotationpolicy.go new file mode 100644 index 00000000000..c92fe27f2fb --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_rotationpolicy.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RotationPolicy struct { + Attributes *KeyRotationPolicyAttributes `json:"attributes,omitempty"` + LifetimeActions *[]LifetimeAction `json:"lifetimeActions,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/model_trigger.go b/resource-manager/keyvault/2024-11-01/keys/model_trigger.go new file mode 100644 index 00000000000..ac603309819 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/model_trigger.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Trigger struct { + TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` + TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/keys/predicates.go b/resource-manager/keyvault/2024-11-01/keys/predicates.go new file mode 100644 index 00000000000..d7bea89219a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/predicates.go @@ -0,0 +1,32 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p KeyOperationPredicate) Matches(input Key) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/keys/version.go b/resource-manager/keyvault/2024-11-01/keys/version.go new file mode 100644 index 00000000000..9fc36badc4e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/keys/version.go @@ -0,0 +1,10 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/keys/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/README.md b/resource-manager/keyvault/2024-11-01/managedhsmkeys/README.md new file mode 100644 index 00000000000..29aa2707474 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/README.md @@ -0,0 +1,107 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsmkeys` Documentation + +The `managedhsmkeys` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsmkeys" +``` + + +### Client Initialization + +```go +client := managedhsmkeys.NewManagedHsmKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedHsmKeysClient.CreateIfNotExist` + +```go +ctx := context.TODO() +id := managedhsmkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName") + +payload := managedhsmkeys.ManagedHsmKeyCreateParameters{ + // ... +} + + +read, err := client.CreateIfNotExist(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmKeysClient.Get` + +```go +ctx := context.TODO() +id := managedhsmkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmKeysClient.GetVersion` + +```go +ctx := context.TODO() +id := managedhsmkeys.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName", "versionName") + +read, err := client.GetVersion(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmKeysClient.List` + +```go +ctx := context.TODO() +id := managedhsmkeys.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedHsmKeysClient.ListVersions` + +```go +ctx := context.TODO() +id := managedhsmkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName") + +// alternatively `client.ListVersions(ctx, id)` can be used to do batched pagination +items, err := client.ListVersionsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/client.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/client.go new file mode 100644 index 00000000000..8270b6fa95d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/client.go @@ -0,0 +1,26 @@ +package managedhsmkeys + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeysClient struct { + Client *resourcemanager.Client +} + +func NewManagedHsmKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedHsmKeysClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedhsmkeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedHsmKeysClient: %+v", err) + } + + return &ManagedHsmKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/constants.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/constants.go new file mode 100644 index 00000000000..cb82cf7396c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/constants.go @@ -0,0 +1,251 @@ +package managedhsmkeys + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletionRecoveryLevel string + +const ( + DeletionRecoveryLevelPurgeable DeletionRecoveryLevel = "Purgeable" + DeletionRecoveryLevelRecoverable DeletionRecoveryLevel = "Recoverable" + DeletionRecoveryLevelRecoverablePositiveProtectedSubscription DeletionRecoveryLevel = "Recoverable+ProtectedSubscription" + DeletionRecoveryLevelRecoverablePositivePurgeable DeletionRecoveryLevel = "Recoverable+Purgeable" +) + +func PossibleValuesForDeletionRecoveryLevel() []string { + return []string{ + string(DeletionRecoveryLevelPurgeable), + string(DeletionRecoveryLevelRecoverable), + string(DeletionRecoveryLevelRecoverablePositiveProtectedSubscription), + string(DeletionRecoveryLevelRecoverablePositivePurgeable), + } +} + +func (s *DeletionRecoveryLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeletionRecoveryLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeletionRecoveryLevel(input string) (*DeletionRecoveryLevel, error) { + vals := map[string]DeletionRecoveryLevel{ + "purgeable": DeletionRecoveryLevelPurgeable, + "recoverable": DeletionRecoveryLevelRecoverable, + "recoverable+protectedsubscription": DeletionRecoveryLevelRecoverablePositiveProtectedSubscription, + "recoverable+purgeable": DeletionRecoveryLevelRecoverablePositivePurgeable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeletionRecoveryLevel(input) + return &out, nil +} + +type JsonWebKeyCurveName string + +const ( + JsonWebKeyCurveNamePNegativeFiveTwoOne JsonWebKeyCurveName = "P-521" + JsonWebKeyCurveNamePNegativeThreeEightFour JsonWebKeyCurveName = "P-384" + JsonWebKeyCurveNamePNegativeTwoFiveSix JsonWebKeyCurveName = "P-256" + JsonWebKeyCurveNamePNegativeTwoFiveSixK JsonWebKeyCurveName = "P-256K" +) + +func PossibleValuesForJsonWebKeyCurveName() []string { + return []string{ + string(JsonWebKeyCurveNamePNegativeFiveTwoOne), + string(JsonWebKeyCurveNamePNegativeThreeEightFour), + string(JsonWebKeyCurveNamePNegativeTwoFiveSix), + string(JsonWebKeyCurveNamePNegativeTwoFiveSixK), + } +} + +func (s *JsonWebKeyCurveName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyCurveName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyCurveName(input string) (*JsonWebKeyCurveName, error) { + vals := map[string]JsonWebKeyCurveName{ + "p-521": JsonWebKeyCurveNamePNegativeFiveTwoOne, + "p-384": JsonWebKeyCurveNamePNegativeThreeEightFour, + "p-256": JsonWebKeyCurveNamePNegativeTwoFiveSix, + "p-256k": JsonWebKeyCurveNamePNegativeTwoFiveSixK, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyCurveName(input) + return &out, nil +} + +type JsonWebKeyOperation string + +const ( + JsonWebKeyOperationDecrypt JsonWebKeyOperation = "decrypt" + JsonWebKeyOperationEncrypt JsonWebKeyOperation = "encrypt" + JsonWebKeyOperationImport JsonWebKeyOperation = "import" + JsonWebKeyOperationRelease JsonWebKeyOperation = "release" + JsonWebKeyOperationSign JsonWebKeyOperation = "sign" + JsonWebKeyOperationUnwrapKey JsonWebKeyOperation = "unwrapKey" + JsonWebKeyOperationVerify JsonWebKeyOperation = "verify" + JsonWebKeyOperationWrapKey JsonWebKeyOperation = "wrapKey" +) + +func PossibleValuesForJsonWebKeyOperation() []string { + return []string{ + string(JsonWebKeyOperationDecrypt), + string(JsonWebKeyOperationEncrypt), + string(JsonWebKeyOperationImport), + string(JsonWebKeyOperationRelease), + string(JsonWebKeyOperationSign), + string(JsonWebKeyOperationUnwrapKey), + string(JsonWebKeyOperationVerify), + string(JsonWebKeyOperationWrapKey), + } +} + +func (s *JsonWebKeyOperation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyOperation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyOperation(input string) (*JsonWebKeyOperation, error) { + vals := map[string]JsonWebKeyOperation{ + "decrypt": JsonWebKeyOperationDecrypt, + "encrypt": JsonWebKeyOperationEncrypt, + "import": JsonWebKeyOperationImport, + "release": JsonWebKeyOperationRelease, + "sign": JsonWebKeyOperationSign, + "unwrapkey": JsonWebKeyOperationUnwrapKey, + "verify": JsonWebKeyOperationVerify, + "wrapkey": JsonWebKeyOperationWrapKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyOperation(input) + return &out, nil +} + +type JsonWebKeyType string + +const ( + JsonWebKeyTypeEC JsonWebKeyType = "EC" + JsonWebKeyTypeECNegativeHSM JsonWebKeyType = "EC-HSM" + JsonWebKeyTypeRSA JsonWebKeyType = "RSA" + JsonWebKeyTypeRSANegativeHSM JsonWebKeyType = "RSA-HSM" +) + +func PossibleValuesForJsonWebKeyType() []string { + return []string{ + string(JsonWebKeyTypeEC), + string(JsonWebKeyTypeECNegativeHSM), + string(JsonWebKeyTypeRSA), + string(JsonWebKeyTypeRSANegativeHSM), + } +} + +func (s *JsonWebKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonWebKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJsonWebKeyType(input string) (*JsonWebKeyType, error) { + vals := map[string]JsonWebKeyType{ + "ec": JsonWebKeyTypeEC, + "ec-hsm": JsonWebKeyTypeECNegativeHSM, + "rsa": JsonWebKeyTypeRSA, + "rsa-hsm": JsonWebKeyTypeRSANegativeHSM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JsonWebKeyType(input) + return &out, nil +} + +type KeyRotationPolicyActionType string + +const ( + KeyRotationPolicyActionTypeNotify KeyRotationPolicyActionType = "notify" + KeyRotationPolicyActionTypeRotate KeyRotationPolicyActionType = "rotate" +) + +func PossibleValuesForKeyRotationPolicyActionType() []string { + return []string{ + string(KeyRotationPolicyActionTypeNotify), + string(KeyRotationPolicyActionTypeRotate), + } +} + +func (s *KeyRotationPolicyActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyRotationPolicyActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyRotationPolicyActionType(input string) (*KeyRotationPolicyActionType, error) { + vals := map[string]KeyRotationPolicyActionType{ + "notify": KeyRotationPolicyActionTypeNotify, + "rotate": KeyRotationPolicyActionTypeRotate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyRotationPolicyActionType(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key.go new file mode 100644 index 00000000000..dd39b431e21 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key.go @@ -0,0 +1,139 @@ +package managedhsmkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&KeyId{}) +} + +var _ resourceids.ResourceId = &KeyId{} + +// KeyId is a struct representing the Resource ID for a Key +type KeyId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string + KeyName string +} + +// NewKeyID returns a new KeyId struct +func NewKeyID(subscriptionId string, resourceGroupName string, managedHSMName string, keyName string) KeyId { + return KeyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + KeyName: keyName, + } +} + +// ParseKeyID parses 'input' into a KeyId +func ParseKeyID(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseKeyIDInsensitively parses 'input' case-insensitively into a KeyId +// note: this method should only be used for API response data and not user input +func ParseKeyIDInsensitively(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *KeyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + if id.KeyName, ok = input.Parsed["keyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "keyName", input) + } + + return nil +} + +// ValidateKeyID checks that 'input' can be parsed as a Key ID +func ValidateKeyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseKeyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Key ID +func (id KeyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s/keys/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName, id.KeyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Key ID +func (id KeyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyName"), + } +} + +// String returns a human-readable description of this Key ID +func (id KeyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + fmt.Sprintf("Key Name: %q", id.KeyName), + } + return fmt.Sprintf("Key (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key_test.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key_test.go new file mode 100644 index 00000000000..b1a5df070b4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_key_test.go @@ -0,0 +1,327 @@ +package managedhsmkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &KeyId{} + +func TestNewKeyID(t *testing.T) { + id := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } + + if id.KeyName != "keyName" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyName") + } +} + +func TestFormatKeyID(t *testing.T) { + actual := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseKeyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestParseKeyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + KeyName: "kEyNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestSegmentsForKeyId(t *testing.T) { + segments := KeyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("KeyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm.go new file mode 100644 index 00000000000..aea1e0c0000 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm.go @@ -0,0 +1,130 @@ +package managedhsmkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedHSMId{}) +} + +var _ resourceids.ResourceId = &ManagedHSMId{} + +// ManagedHSMId is a struct representing the Resource ID for a Managed H S M +type ManagedHSMId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string +} + +// NewManagedHSMID returns a new ManagedHSMId struct +func NewManagedHSMID(subscriptionId string, resourceGroupName string, managedHSMName string) ManagedHSMId { + return ManagedHSMId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + } +} + +// ParseManagedHSMID parses 'input' into a ManagedHSMId +func ParseManagedHSMID(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedHSMIDInsensitively parses 'input' case-insensitively into a ManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseManagedHSMIDInsensitively(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + return nil +} + +// ValidateManagedHSMID checks that 'input' can be parsed as a Managed H S M ID +func ValidateManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed H S M ID +func (id ManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed H S M ID +func (id ManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + } +} + +// String returns a human-readable description of this Managed H S M ID +func (id ManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + } + return fmt.Sprintf("Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm_test.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm_test.go new file mode 100644 index 00000000000..7942622b058 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_managedhsm_test.go @@ -0,0 +1,282 @@ +package managedhsmkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedHSMId{} + +func TestNewManagedHSMID(t *testing.T) { + id := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } +} + +func TestFormatManagedHSMID(t *testing.T) { + actual := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestParseManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestSegmentsForManagedHSMId(t *testing.T) { + segments := ManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version.go new file mode 100644 index 00000000000..fdf99d70b75 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version.go @@ -0,0 +1,148 @@ +package managedhsmkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionId{}) +} + +var _ resourceids.ResourceId = &VersionId{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string + KeyName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(subscriptionId string, resourceGroupName string, managedHSMName string, keyName string, versionName string) VersionId { + return VersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + KeyName: keyName, + VersionName: versionName, + } +} + +// ParseVersionID parses 'input' into a VersionId +func ParseVersionID(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionIDInsensitively parses 'input' case-insensitively into a VersionId +// note: this method should only be used for API response data and not user input +func ParseVersionIDInsensitively(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + if id.KeyName, ok = input.Parsed["keyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "keyName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateVersionID checks that 'input' can be parsed as a Version ID +func ValidateVersionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version ID +func (id VersionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s/keys/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName, id.KeyName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version ID +func (id VersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Version ID +func (id VersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + fmt.Sprintf("Key Name: %q", id.KeyName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version_test.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version_test.go new file mode 100644 index 00000000000..562636f04e4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/id_version_test.go @@ -0,0 +1,372 @@ +package managedhsmkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VersionId{} + +func TestNewVersionID(t *testing.T) { + id := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName", "versionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } + + if id.KeyName != "keyName" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "keyName", "versionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + KeyName: "keyName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + KeyName: "keyName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/keys/keyName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + KeyName: "kEyNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/kEyS/kEyNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForVersionId(t *testing.T) { + segments := VersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_createifnotexist.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_createifnotexist.go new file mode 100644 index 00000000000..15d09c223c9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_createifnotexist.go @@ -0,0 +1,57 @@ +package managedhsmkeys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateIfNotExistOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsmKey +} + +// CreateIfNotExist ... +func (c ManagedHsmKeysClient) CreateIfNotExist(ctx context.Context, id KeyId, input ManagedHsmKeyCreateParameters) (result CreateIfNotExistOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedHsmKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_get.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_get.go new file mode 100644 index 00000000000..dc29f2e8cd6 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_get.go @@ -0,0 +1,53 @@ +package managedhsmkeys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsmKey +} + +// Get ... +func (c ManagedHsmKeysClient) Get(ctx context.Context, id KeyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedHsmKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_getversion.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_getversion.go new file mode 100644 index 00000000000..1301a59a862 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_getversion.go @@ -0,0 +1,53 @@ +package managedhsmkeys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetVersionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsmKey +} + +// GetVersion ... +func (c ManagedHsmKeysClient) GetVersion(ctx context.Context, id VersionId) (result GetVersionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedHsmKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_list.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_list.go new file mode 100644 index 00000000000..8cc0898e8b5 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_list.go @@ -0,0 +1,105 @@ +package managedhsmkeys + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedHsmKey +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedHsmKey +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ManagedHsmKeysClient) List(ctx context.Context, id ManagedHSMId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/keys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedHsmKey `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ManagedHsmKeysClient) ListComplete(ctx context.Context, id ManagedHSMId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ManagedHsmKeyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedHsmKeysClient) ListCompleteMatchingPredicate(ctx context.Context, id ManagedHSMId, predicate ManagedHsmKeyOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ManagedHsmKey, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_listversions.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_listversions.go new file mode 100644 index 00000000000..cd76bd50eda --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/method_listversions.go @@ -0,0 +1,105 @@ +package managedhsmkeys + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListVersionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedHsmKey +} + +type ListVersionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedHsmKey +} + +type ListVersionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListVersionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListVersions ... +func (c ManagedHsmKeysClient) ListVersions(ctx context.Context, id KeyId) (result ListVersionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListVersionsCustomPager{}, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedHsmKey `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListVersionsComplete retrieves all the results into a single object +func (c ManagedHsmKeysClient) ListVersionsComplete(ctx context.Context, id KeyId) (ListVersionsCompleteResult, error) { + return c.ListVersionsCompleteMatchingPredicate(ctx, id, ManagedHsmKeyOperationPredicate{}) +} + +// ListVersionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedHsmKeysClient) ListVersionsCompleteMatchingPredicate(ctx context.Context, id KeyId, predicate ManagedHsmKeyOperationPredicate) (result ListVersionsCompleteResult, err error) { + items := make([]ManagedHsmKey, 0) + + resp, err := c.ListVersions(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListVersionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmaction.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmaction.go new file mode 100644 index 00000000000..bd63ab71bf5 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmaction.go @@ -0,0 +1,8 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmAction struct { + Type *KeyRotationPolicyActionType `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkey.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkey.go new file mode 100644 index 00000000000..faaabece070 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkey.go @@ -0,0 +1,12 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKey struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ManagedHsmKeyProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyattributes.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyattributes.go new file mode 100644 index 00000000000..4fc2ca3827f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyattributes.go @@ -0,0 +1,14 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyAttributes struct { + Created *int64 `json:"created,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Exp *int64 `json:"exp,omitempty"` + Exportable *bool `json:"exportable,omitempty"` + Nbf *int64 `json:"nbf,omitempty"` + RecoveryLevel *DeletionRecoveryLevel `json:"recoveryLevel,omitempty"` + Updated *int64 `json:"updated,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeycreateparameters.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeycreateparameters.go new file mode 100644 index 00000000000..c0b466e274b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeycreateparameters.go @@ -0,0 +1,9 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyCreateParameters struct { + Properties ManagedHsmKeyProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyproperties.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyproperties.go new file mode 100644 index 00000000000..f2401d5e9ae --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyproperties.go @@ -0,0 +1,16 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyProperties struct { + Attributes *ManagedHsmKeyAttributes `json:"attributes,omitempty"` + CurveName *JsonWebKeyCurveName `json:"curveName,omitempty"` + KeyOps *[]JsonWebKeyOperation `json:"keyOps,omitempty"` + KeySize *int64 `json:"keySize,omitempty"` + KeyUri *string `json:"keyUri,omitempty"` + KeyUriWithVersion *string `json:"keyUriWithVersion,omitempty"` + Kty *JsonWebKeyType `json:"kty,omitempty"` + ReleasePolicy *ManagedHsmKeyReleasePolicy `json:"release_policy,omitempty"` + RotationPolicy *ManagedHsmRotationPolicy `json:"rotationPolicy,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyreleasepolicy.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyreleasepolicy.go new file mode 100644 index 00000000000..11bf1ae9935 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyreleasepolicy.go @@ -0,0 +1,9 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyReleasePolicy struct { + ContentType *string `json:"contentType,omitempty"` + Data *string `json:"data,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyrotationpolicyattributes.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyrotationpolicyattributes.go new file mode 100644 index 00000000000..4b6109ab2f9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmkeyrotationpolicyattributes.go @@ -0,0 +1,10 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyRotationPolicyAttributes struct { + Created *int64 `json:"created,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Updated *int64 `json:"updated,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmlifetimeaction.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmlifetimeaction.go new file mode 100644 index 00000000000..030b340464b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmlifetimeaction.go @@ -0,0 +1,9 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmLifetimeAction struct { + Action *ManagedHsmAction `json:"action,omitempty"` + Trigger *ManagedHsmTrigger `json:"trigger,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmrotationpolicy.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmrotationpolicy.go new file mode 100644 index 00000000000..a45f7da6869 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmrotationpolicy.go @@ -0,0 +1,9 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmRotationPolicy struct { + Attributes *ManagedHsmKeyRotationPolicyAttributes `json:"attributes,omitempty"` + LifetimeActions *[]ManagedHsmLifetimeAction `json:"lifetimeActions,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmtrigger.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmtrigger.go new file mode 100644 index 00000000000..a2783185ade --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/model_managedhsmtrigger.go @@ -0,0 +1,9 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmTrigger struct { + TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` + TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/predicates.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/predicates.go new file mode 100644 index 00000000000..ed22e02a4b0 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/predicates.go @@ -0,0 +1,27 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmKeyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedHsmKeyOperationPredicate) Matches(input ManagedHsmKey) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsmkeys/version.go b/resource-manager/keyvault/2024-11-01/managedhsmkeys/version.go new file mode 100644 index 00000000000..806e9c6e02d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsmkeys/version.go @@ -0,0 +1,10 @@ +package managedhsmkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedhsmkeys/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/README.md b/resource-manager/keyvault/2024-11-01/managedhsms/README.md new file mode 100644 index 00000000000..02d0b8a475b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/README.md @@ -0,0 +1,183 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsms` Documentation + +The `managedhsms` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/managedhsms" +``` + + +### Client Initialization + +```go +client := managedhsms.NewManagedHsmsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedHsmsClient.CheckMhsmNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := managedhsms.CheckMhsmNameAvailabilityParameters{ + // ... +} + + +read, err := client.CheckMhsmNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedhsms.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +payload := managedhsms.ManagedHsm{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedHsmsClient.Delete` + +```go +ctx := context.TODO() +id := managedhsms.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedHsmsClient.Get` + +```go +ctx := context.TODO() +id := managedhsms.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmsClient.GetDeleted` + +```go +ctx := context.TODO() +id := managedhsms.NewDeletedManagedHSMID("12345678-1234-9876-4563-123456789012", "locationName", "deletedManagedHSMName") + +read, err := client.GetDeleted(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedHsmsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, managedhsms.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, managedhsms.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedHsmsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, managedhsms.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, managedhsms.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedHsmsClient.ListDeleted` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListDeleted(ctx, id)` can be used to do batched pagination +items, err := client.ListDeletedComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedHsmsClient.PurgeDeleted` + +```go +ctx := context.TODO() +id := managedhsms.NewDeletedManagedHSMID("12345678-1234-9876-4563-123456789012", "locationName", "deletedManagedHSMName") + +if err := client.PurgeDeletedThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedHsmsClient.Update` + +```go +ctx := context.TODO() +id := managedhsms.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +payload := managedhsms.ManagedHsm{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/client.go b/resource-manager/keyvault/2024-11-01/managedhsms/client.go new file mode 100644 index 00000000000..4702a1257d3 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/client.go @@ -0,0 +1,26 @@ +package managedhsms + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmsClient struct { + Client *resourcemanager.Client +} + +func NewManagedHsmsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedHsmsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedhsms", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedHsmsClient: %+v", err) + } + + return &ManagedHsmsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/constants.go b/resource-manager/keyvault/2024-11-01/managedhsms/constants.go new file mode 100644 index 00000000000..89c88645885 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/constants.go @@ -0,0 +1,603 @@ +package managedhsms + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type ActivationStatus string + +const ( + ActivationStatusActive ActivationStatus = "Active" + ActivationStatusFailed ActivationStatus = "Failed" + ActivationStatusNotActivated ActivationStatus = "NotActivated" + ActivationStatusUnknown ActivationStatus = "Unknown" +) + +func PossibleValuesForActivationStatus() []string { + return []string{ + string(ActivationStatusActive), + string(ActivationStatusFailed), + string(ActivationStatusNotActivated), + string(ActivationStatusUnknown), + } +} + +func (s *ActivationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActivationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActivationStatus(input string) (*ActivationStatus, error) { + vals := map[string]ActivationStatus{ + "active": ActivationStatusActive, + "failed": ActivationStatusFailed, + "notactivated": ActivationStatusNotActivated, + "unknown": ActivationStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActivationStatus(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "default" + CreateModeRecover CreateMode = "recover" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeRecover), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "recover": CreateModeRecover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type GeoReplicationRegionProvisioningState string + +const ( + GeoReplicationRegionProvisioningStateCleanup GeoReplicationRegionProvisioningState = "Cleanup" + GeoReplicationRegionProvisioningStateDeleting GeoReplicationRegionProvisioningState = "Deleting" + GeoReplicationRegionProvisioningStateFailed GeoReplicationRegionProvisioningState = "Failed" + GeoReplicationRegionProvisioningStatePreprovisioning GeoReplicationRegionProvisioningState = "Preprovisioning" + GeoReplicationRegionProvisioningStateProvisioning GeoReplicationRegionProvisioningState = "Provisioning" + GeoReplicationRegionProvisioningStateSucceeded GeoReplicationRegionProvisioningState = "Succeeded" +) + +func PossibleValuesForGeoReplicationRegionProvisioningState() []string { + return []string{ + string(GeoReplicationRegionProvisioningStateCleanup), + string(GeoReplicationRegionProvisioningStateDeleting), + string(GeoReplicationRegionProvisioningStateFailed), + string(GeoReplicationRegionProvisioningStatePreprovisioning), + string(GeoReplicationRegionProvisioningStateProvisioning), + string(GeoReplicationRegionProvisioningStateSucceeded), + } +} + +func (s *GeoReplicationRegionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGeoReplicationRegionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGeoReplicationRegionProvisioningState(input string) (*GeoReplicationRegionProvisioningState, error) { + vals := map[string]GeoReplicationRegionProvisioningState{ + "cleanup": GeoReplicationRegionProvisioningStateCleanup, + "deleting": GeoReplicationRegionProvisioningStateDeleting, + "failed": GeoReplicationRegionProvisioningStateFailed, + "preprovisioning": GeoReplicationRegionProvisioningStatePreprovisioning, + "provisioning": GeoReplicationRegionProvisioningStateProvisioning, + "succeeded": GeoReplicationRegionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GeoReplicationRegionProvisioningState(input) + return &out, nil +} + +type ManagedHsmSkuFamily string + +const ( + ManagedHsmSkuFamilyB ManagedHsmSkuFamily = "B" + ManagedHsmSkuFamilyC ManagedHsmSkuFamily = "C" +) + +func PossibleValuesForManagedHsmSkuFamily() []string { + return []string{ + string(ManagedHsmSkuFamilyB), + string(ManagedHsmSkuFamilyC), + } +} + +func (s *ManagedHsmSkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuFamily(input string) (*ManagedHsmSkuFamily, error) { + vals := map[string]ManagedHsmSkuFamily{ + "b": ManagedHsmSkuFamilyB, + "c": ManagedHsmSkuFamilyC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuFamily(input) + return &out, nil +} + +type ManagedHsmSkuName string + +const ( + ManagedHsmSkuNameCustomBSix ManagedHsmSkuName = "Custom_B6" + ManagedHsmSkuNameCustomBThreeTwo ManagedHsmSkuName = "Custom_B32" + ManagedHsmSkuNameCustomCFourTwo ManagedHsmSkuName = "Custom_C42" + ManagedHsmSkuNameCustomCOneZero ManagedHsmSkuName = "Custom_C10" + ManagedHsmSkuNameStandardBOne ManagedHsmSkuName = "Standard_B1" +) + +func PossibleValuesForManagedHsmSkuName() []string { + return []string{ + string(ManagedHsmSkuNameCustomBSix), + string(ManagedHsmSkuNameCustomBThreeTwo), + string(ManagedHsmSkuNameCustomCFourTwo), + string(ManagedHsmSkuNameCustomCOneZero), + string(ManagedHsmSkuNameStandardBOne), + } +} + +func (s *ManagedHsmSkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuName(input string) (*ManagedHsmSkuName, error) { + vals := map[string]ManagedHsmSkuName{ + "custom_b6": ManagedHsmSkuNameCustomBSix, + "custom_b32": ManagedHsmSkuNameCustomBThreeTwo, + "custom_c42": ManagedHsmSkuNameCustomCFourTwo, + "custom_c10": ManagedHsmSkuNameCustomCOneZero, + "standard_b1": ManagedHsmSkuNameStandardBOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuName(input) + return &out, nil +} + +type NetworkRuleAction string + +const ( + NetworkRuleActionAllow NetworkRuleAction = "Allow" + NetworkRuleActionDeny NetworkRuleAction = "Deny" +) + +func PossibleValuesForNetworkRuleAction() []string { + return []string{ + string(NetworkRuleActionAllow), + string(NetworkRuleActionDeny), + } +} + +func (s *NetworkRuleAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleAction(input string) (*NetworkRuleAction, error) { + vals := map[string]NetworkRuleAction{ + "allow": NetworkRuleActionAllow, + "deny": NetworkRuleActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleAction(input) + return &out, nil +} + +type NetworkRuleBypassOptions string + +const ( + NetworkRuleBypassOptionsAzureServices NetworkRuleBypassOptions = "AzureServices" + NetworkRuleBypassOptionsNone NetworkRuleBypassOptions = "None" +) + +func PossibleValuesForNetworkRuleBypassOptions() []string { + return []string{ + string(NetworkRuleBypassOptionsAzureServices), + string(NetworkRuleBypassOptionsNone), + } +} + +func (s *NetworkRuleBypassOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleBypassOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleBypassOptions(input string) (*NetworkRuleBypassOptions, error) { + vals := map[string]NetworkRuleBypassOptions{ + "azureservices": NetworkRuleBypassOptionsAzureServices, + "none": NetworkRuleBypassOptionsNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleBypassOptions(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateDisconnected PrivateEndpointConnectionProvisioningState = "Disconnected" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateDisconnected), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + string(PrivateEndpointConnectionProvisioningStateUpdating), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "disconnected": PrivateEndpointConnectionProvisioningStateDisconnected, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + "updating": PrivateEndpointConnectionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusDisconnected PrivateEndpointServiceConnectionStatus = "Disconnected" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusDisconnected), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "disconnected": PrivateEndpointServiceConnectionStatusDisconnected, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateActivated ProvisioningState = "Activated" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateRestoring ProvisioningState = "Restoring" + ProvisioningStateSecurityDomainRestore ProvisioningState = "SecurityDomainRestore" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateActivated), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateRestoring), + string(ProvisioningStateSecurityDomainRestore), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "activated": ProvisioningStateActivated, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "restoring": ProvisioningStateRestoring, + "securitydomainrestore": ProvisioningStateSecurityDomainRestore, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type Reason string + +const ( + ReasonAccountNameInvalid Reason = "AccountNameInvalid" + ReasonAlreadyExists Reason = "AlreadyExists" +) + +func PossibleValuesForReason() []string { + return []string{ + string(ReasonAccountNameInvalid), + string(ReasonAlreadyExists), + } +} + +func (s *Reason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReason(input string) (*Reason, error) { + vals := map[string]Reason{ + "accountnameinvalid": ReasonAccountNameInvalid, + "alreadyexists": ReasonAlreadyExists, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Reason(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm.go b/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm.go new file mode 100644 index 00000000000..38f9e319b85 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm.go @@ -0,0 +1,130 @@ +package managedhsms + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeletedManagedHSMId{}) +} + +var _ resourceids.ResourceId = &DeletedManagedHSMId{} + +// DeletedManagedHSMId is a struct representing the Resource ID for a Deleted Managed H S M +type DeletedManagedHSMId struct { + SubscriptionId string + LocationName string + DeletedManagedHSMName string +} + +// NewDeletedManagedHSMID returns a new DeletedManagedHSMId struct +func NewDeletedManagedHSMID(subscriptionId string, locationName string, deletedManagedHSMName string) DeletedManagedHSMId { + return DeletedManagedHSMId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + DeletedManagedHSMName: deletedManagedHSMName, + } +} + +// ParseDeletedManagedHSMID parses 'input' into a DeletedManagedHSMId +func ParseDeletedManagedHSMID(input string) (*DeletedManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedManagedHSMIDInsensitively parses 'input' case-insensitively into a DeletedManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseDeletedManagedHSMIDInsensitively(input string) (*DeletedManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.DeletedManagedHSMName, ok = input.Parsed["deletedManagedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedManagedHSMName", input) + } + + return nil +} + +// ValidateDeletedManagedHSMID checks that 'input' can be parsed as a Deleted Managed H S M ID +func ValidateDeletedManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDeletedManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Managed H S M ID +func (id DeletedManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.KeyVault/locations/%s/deletedManagedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.DeletedManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Managed H S M ID +func (id DeletedManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticDeletedManagedHSMs", "deletedManagedHSMs", "deletedManagedHSMs"), + resourceids.UserSpecifiedSegment("deletedManagedHSMName", "deletedManagedHSMName"), + } +} + +// String returns a human-readable description of this Deleted Managed H S M ID +func (id DeletedManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Deleted Managed H S M Name: %q", id.DeletedManagedHSMName), + } + return fmt.Sprintf("Deleted Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm_test.go b/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm_test.go new file mode 100644 index 00000000000..6a00580931a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/id_deletedmanagedhsm_test.go @@ -0,0 +1,282 @@ +package managedhsms + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DeletedManagedHSMId{} + +func TestNewDeletedManagedHSMID(t *testing.T) { + id := NewDeletedManagedHSMID("12345678-1234-9876-4563-123456789012", "locationName", "deletedManagedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.DeletedManagedHSMName != "deletedManagedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedManagedHSMName'", id.DeletedManagedHSMName, "deletedManagedHSMName") + } +} + +func TestFormatDeletedManagedHSMID(t *testing.T) { + actual := NewDeletedManagedHSMID("12345678-1234-9876-4563-123456789012", "locationName", "deletedManagedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs/deletedManagedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs/deletedManagedHSMName", + Expected: &DeletedManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedManagedHSMName: "deletedManagedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs/deletedManagedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedManagedHSMName != v.Expected.DeletedManagedHSMName { + t.Fatalf("Expected %q but got %q for DeletedManagedHSMName", v.Expected.DeletedManagedHSMName, actual.DeletedManagedHSMName) + } + + } +} + +func TestParseDeletedManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdMaNaGeDhSmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs/deletedManagedHSMName", + Expected: &DeletedManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedManagedHSMName: "deletedManagedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedManagedHSMs/deletedManagedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdMaNaGeDhSmS/dElEtEdMaNaGeDhSmNaMe", + Expected: &DeletedManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + DeletedManagedHSMName: "dElEtEdMaNaGeDhSmNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdMaNaGeDhSmS/dElEtEdMaNaGeDhSmNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedManagedHSMName != v.Expected.DeletedManagedHSMName { + t.Fatalf("Expected %q but got %q for DeletedManagedHSMName", v.Expected.DeletedManagedHSMName, actual.DeletedManagedHSMName) + } + + } +} + +func TestSegmentsForDeletedManagedHSMId(t *testing.T) { + segments := DeletedManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm.go b/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm.go new file mode 100644 index 00000000000..53b05210ec3 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm.go @@ -0,0 +1,130 @@ +package managedhsms + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedHSMId{}) +} + +var _ resourceids.ResourceId = &ManagedHSMId{} + +// ManagedHSMId is a struct representing the Resource ID for a Managed H S M +type ManagedHSMId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string +} + +// NewManagedHSMID returns a new ManagedHSMId struct +func NewManagedHSMID(subscriptionId string, resourceGroupName string, managedHSMName string) ManagedHSMId { + return ManagedHSMId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + } +} + +// ParseManagedHSMID parses 'input' into a ManagedHSMId +func ParseManagedHSMID(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedHSMIDInsensitively parses 'input' case-insensitively into a ManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseManagedHSMIDInsensitively(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + return nil +} + +// ValidateManagedHSMID checks that 'input' can be parsed as a Managed H S M ID +func ValidateManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed H S M ID +func (id ManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed H S M ID +func (id ManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + } +} + +// String returns a human-readable description of this Managed H S M ID +func (id ManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + } + return fmt.Sprintf("Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm_test.go b/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm_test.go new file mode 100644 index 00000000000..67cd6ac27d0 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/id_managedhsm_test.go @@ -0,0 +1,282 @@ +package managedhsms + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedHSMId{} + +func TestNewManagedHSMID(t *testing.T) { + id := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } +} + +func TestFormatManagedHSMID(t *testing.T) { + actual := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestParseManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestSegmentsForManagedHSMId(t *testing.T) { + segments := ManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_checkmhsmnameavailability.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_checkmhsmnameavailability.go new file mode 100644 index 00000000000..3f7800d6c65 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_checkmhsmnameavailability.go @@ -0,0 +1,59 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckMhsmNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckMhsmNameAvailabilityResult +} + +// CheckMhsmNameAvailability ... +func (c ManagedHsmsClient) CheckMhsmNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckMhsmNameAvailabilityParameters) (result CheckMhsmNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/checkMhsmNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckMhsmNameAvailabilityResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_createorupdate.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_createorupdate.go new file mode 100644 index 00000000000..006c18214b9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsm +} + +// CreateOrUpdate ... +func (c ManagedHsmsClient) CreateOrUpdate(ctx context.Context, id ManagedHSMId, input ManagedHsm) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedHsmsClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedHSMId, input ManagedHsm) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_delete.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_delete.go new file mode 100644 index 00000000000..6f16d635189 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_delete.go @@ -0,0 +1,71 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedHsmsClient) Delete(ctx context.Context, id ManagedHSMId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ManagedHsmsClient) DeleteThenPoll(ctx context.Context, id ManagedHSMId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_get.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_get.go new file mode 100644 index 00000000000..8069e0a5619 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_get.go @@ -0,0 +1,54 @@ +package managedhsms + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsm +} + +// Get ... +func (c ManagedHsmsClient) Get(ctx context.Context, id ManagedHSMId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ManagedHsm + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_getdeleted.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_getdeleted.go new file mode 100644 index 00000000000..7c16558dcfc --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_getdeleted.go @@ -0,0 +1,53 @@ +package managedhsms + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDeletedOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeletedManagedHsm +} + +// GetDeleted ... +func (c ManagedHsmsClient) GetDeleted(ctx context.Context, id DeletedManagedHSMId) (result GetDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DeletedManagedHsm + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_listbyresourcegroup.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_listbyresourcegroup.go new file mode 100644 index 00000000000..ca2f0d08e04 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_listbyresourcegroup.go @@ -0,0 +1,135 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedHsm +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedHsm +} + +type ListByResourceGroupOperationOptions struct { + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ManagedHsmsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/managedHSMs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedHsm `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c ManagedHsmsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ManagedHsmOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedHsmsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ManagedHsmOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ManagedHsm, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_listbysubscription.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_listbysubscription.go new file mode 100644 index 00000000000..6f660327ce7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_listbysubscription.go @@ -0,0 +1,135 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedHsm +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedHsm +} + +type ListBySubscriptionOperationOptions struct { + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ManagedHsmsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/managedHSMs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedHsm `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c ManagedHsmsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, ManagedHsmOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedHsmsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate ManagedHsmOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ManagedHsm, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_listdeleted.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_listdeleted.go new file mode 100644 index 00000000000..0f1bce806ce --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_listdeleted.go @@ -0,0 +1,106 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListDeletedOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeletedManagedHsm +} + +type ListDeletedCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedManagedHsm +} + +type ListDeletedCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListDeletedCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListDeleted ... +func (c ManagedHsmsClient) ListDeleted(ctx context.Context, id commonids.SubscriptionId) (result ListDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListDeletedCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/deletedManagedHSMs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DeletedManagedHsm `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListDeletedComplete retrieves all the results into a single object +func (c ManagedHsmsClient) ListDeletedComplete(ctx context.Context, id commonids.SubscriptionId) (ListDeletedCompleteResult, error) { + return c.ListDeletedCompleteMatchingPredicate(ctx, id, DeletedManagedHsmOperationPredicate{}) +} + +// ListDeletedCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedHsmsClient) ListDeletedCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DeletedManagedHsmOperationPredicate) (result ListDeletedCompleteResult, err error) { + items := make([]DeletedManagedHsm, 0) + + resp, err := c.ListDeleted(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListDeletedCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_purgedeleted.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_purgedeleted.go new file mode 100644 index 00000000000..efe27946375 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_purgedeleted.go @@ -0,0 +1,69 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeDeletedOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PurgeDeleted ... +func (c ManagedHsmsClient) PurgeDeleted(ctx context.Context, id DeletedManagedHSMId) (result PurgeDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/purge", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PurgeDeletedThenPoll performs PurgeDeleted then polls until it's completed +func (c ManagedHsmsClient) PurgeDeletedThenPoll(ctx context.Context, id DeletedManagedHSMId) error { + result, err := c.PurgeDeleted(ctx, id) + if err != nil { + return fmt.Errorf("performing PurgeDeleted: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PurgeDeleted: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/method_update.go b/resource-manager/keyvault/2024-11-01/managedhsms/method_update.go new file mode 100644 index 00000000000..d9686ae4c4a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/method_update.go @@ -0,0 +1,75 @@ +package managedhsms + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedHsm +} + +// Update ... +func (c ManagedHsmsClient) Update(ctx context.Context, id ManagedHSMId, input ManagedHsm) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ManagedHsmsClient) UpdateThenPoll(ctx context.Context, id ManagedHSMId, input ManagedHsm) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityparameters.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityparameters.go new file mode 100644 index 00000000000..a3d8ea5b0e2 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityparameters.go @@ -0,0 +1,8 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckMhsmNameAvailabilityParameters struct { + Name string `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityresult.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityresult.go new file mode 100644 index 00000000000..f8c2c2d2995 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_checkmhsmnameavailabilityresult.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckMhsmNameAvailabilityResult struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *Reason `json:"reason,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsm.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsm.go new file mode 100644 index 00000000000..ae5e8a11615 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsm.go @@ -0,0 +1,11 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedManagedHsm struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedManagedHsmProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsmproperties.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsmproperties.go new file mode 100644 index 00000000000..5093466f02e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_deletedmanagedhsmproperties.go @@ -0,0 +1,43 @@ +package managedhsms + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedManagedHsmProperties struct { + DeletionDate *string `json:"deletionDate,omitempty"` + Location *string `json:"location,omitempty"` + MhsmId *string `json:"mhsmId,omitempty"` + PurgeProtectionEnabled *bool `json:"purgeProtectionEnabled,omitempty"` + ScheduledPurgeDate *string `json:"scheduledPurgeDate,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} + +func (o *DeletedManagedHsmProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedManagedHsmProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *DeletedManagedHsmProperties) GetScheduledPurgeDateAsTime() (*time.Time, error) { + if o.ScheduledPurgeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduledPurgeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedManagedHsmProperties) SetScheduledPurgeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduledPurgeDate = &formatted +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsm.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsm.go new file mode 100644 index 00000000000..ba490099215 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsm.go @@ -0,0 +1,21 @@ +package managedhsms + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsm struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedHsmProperties `json:"properties,omitempty"` + Sku *ManagedHsmSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmproperties.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmproperties.go new file mode 100644 index 00000000000..27d30dbab01 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmproperties.go @@ -0,0 +1,40 @@ +package managedhsms + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmProperties struct { + CreateMode *CreateMode `json:"createMode,omitempty"` + EnablePurgeProtection *bool `json:"enablePurgeProtection,omitempty"` + EnableSoftDelete *bool `json:"enableSoftDelete,omitempty"` + HsmUri *string `json:"hsmUri,omitempty"` + InitialAdminObjectIds *[]string `json:"initialAdminObjectIds,omitempty"` + NetworkAcls *MHSMNetworkRuleSet `json:"networkAcls,omitempty"` + PrivateEndpointConnections *[]MHSMPrivateEndpointConnectionItem `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + Regions *[]MHSMGeoReplicatedRegion `json:"regions,omitempty"` + ScheduledPurgeDate *string `json:"scheduledPurgeDate,omitempty"` + SecurityDomainProperties *ManagedHSMSecurityDomainProperties `json:"securityDomainProperties,omitempty"` + SoftDeleteRetentionInDays *int64 `json:"softDeleteRetentionInDays,omitempty"` + StatusMessage *string `json:"statusMessage,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} + +func (o *ManagedHsmProperties) GetScheduledPurgeDateAsTime() (*time.Time, error) { + if o.ScheduledPurgeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduledPurgeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedHsmProperties) SetScheduledPurgeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduledPurgeDate = &formatted +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsecuritydomainproperties.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsecuritydomainproperties.go new file mode 100644 index 00000000000..63842e56813 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsecuritydomainproperties.go @@ -0,0 +1,9 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHSMSecurityDomainProperties struct { + ActivationStatus *ActivationStatus `json:"activationStatus,omitempty"` + ActivationStatusMessage *string `json:"activationStatusMessage,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsku.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsku.go new file mode 100644 index 00000000000..61dcd5e3b98 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_managedhsmsku.go @@ -0,0 +1,9 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmSku struct { + Family ManagedHsmSkuFamily `json:"family"` + Name ManagedHsmSkuName `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmgeoreplicatedregion.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmgeoreplicatedregion.go new file mode 100644 index 00000000000..02ff4ffdc7d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmgeoreplicatedregion.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMGeoReplicatedRegion struct { + IsPrimary *bool `json:"isPrimary,omitempty"` + Name *string `json:"name,omitempty"` + ProvisioningState *GeoReplicationRegionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmiprule.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmiprule.go new file mode 100644 index 00000000000..6fb2abdeef9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmiprule.go @@ -0,0 +1,8 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMIPRule struct { + Value string `json:"value"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmnetworkruleset.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmnetworkruleset.go new file mode 100644 index 00000000000..2fc81ecae8d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmnetworkruleset.go @@ -0,0 +1,11 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMNetworkRuleSet struct { + Bypass *NetworkRuleBypassOptions `json:"bypass,omitempty"` + DefaultAction *NetworkRuleAction `json:"defaultAction,omitempty"` + IPRules *[]MHSMIPRule `json:"ipRules,omitempty"` + VirtualNetworkRules *[]MHSMVirtualNetworkRule `json:"virtualNetworkRules,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpoint.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpoint.go new file mode 100644 index 00000000000..dadd1b65b93 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpoint.go @@ -0,0 +1,8 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionitem.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionitem.go new file mode 100644 index 00000000000..d7b577af988 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionitem.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionItem struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Properties *MHSMPrivateEndpointConnectionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionproperties.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..e91a4b16dec --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionProperties struct { + PrivateEndpoint *MHSMPrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *MHSMPrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivatelinkserviceconnectionstate.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..83b45a02518 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmprivatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmvirtualnetworkrule.go b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmvirtualnetworkrule.go new file mode 100644 index 00000000000..3daa2f4233b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/model_mhsmvirtualnetworkrule.go @@ -0,0 +1,8 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMVirtualNetworkRule struct { + Id string `json:"id"` +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/predicates.go b/resource-manager/keyvault/2024-11-01/managedhsms/predicates.go new file mode 100644 index 00000000000..598d2e6d12b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/predicates.go @@ -0,0 +1,55 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedManagedHsmOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeletedManagedHsmOperationPredicate) Matches(input DeletedManagedHsm) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ManagedHsmOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedHsmOperationPredicate) Matches(input ManagedHsm) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/managedhsms/version.go b/resource-manager/keyvault/2024-11-01/managedhsms/version.go new file mode 100644 index 00000000000..fe478e992b5 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/managedhsms/version.go @@ -0,0 +1,10 @@ +package managedhsms + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedhsms/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/README.md b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/README.md new file mode 100644 index 00000000000..10bec5d082d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections` Documentation + +The `mhsmlistprivateendpointconnections` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections" +``` + + +### Client Initialization + +```go +client := mhsmlistprivateendpointconnections.NewMHSMListPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MHSMListPrivateEndpointConnectionsClient.MHSMPrivateEndpointConnectionsListByResource` + +```go +ctx := context.TODO() +id := mhsmlistprivateendpointconnections.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +// alternatively `client.MHSMPrivateEndpointConnectionsListByResource(ctx, id)` can be used to do batched pagination +items, err := client.MHSMPrivateEndpointConnectionsListByResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/client.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/client.go new file mode 100644 index 00000000000..ba5797c489c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/client.go @@ -0,0 +1,26 @@ +package mhsmlistprivateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMListPrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewMHSMListPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MHSMListPrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "mhsmlistprivateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MHSMListPrivateEndpointConnectionsClient: %+v", err) + } + + return &MHSMListPrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/constants.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/constants.go new file mode 100644 index 00000000000..afd446d0a0c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/constants.go @@ -0,0 +1,239 @@ +package mhsmlistprivateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type ManagedHsmSkuFamily string + +const ( + ManagedHsmSkuFamilyB ManagedHsmSkuFamily = "B" + ManagedHsmSkuFamilyC ManagedHsmSkuFamily = "C" +) + +func PossibleValuesForManagedHsmSkuFamily() []string { + return []string{ + string(ManagedHsmSkuFamilyB), + string(ManagedHsmSkuFamilyC), + } +} + +func (s *ManagedHsmSkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuFamily(input string) (*ManagedHsmSkuFamily, error) { + vals := map[string]ManagedHsmSkuFamily{ + "b": ManagedHsmSkuFamilyB, + "c": ManagedHsmSkuFamilyC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuFamily(input) + return &out, nil +} + +type ManagedHsmSkuName string + +const ( + ManagedHsmSkuNameCustomBSix ManagedHsmSkuName = "Custom_B6" + ManagedHsmSkuNameCustomBThreeTwo ManagedHsmSkuName = "Custom_B32" + ManagedHsmSkuNameCustomCFourTwo ManagedHsmSkuName = "Custom_C42" + ManagedHsmSkuNameCustomCOneZero ManagedHsmSkuName = "Custom_C10" + ManagedHsmSkuNameStandardBOne ManagedHsmSkuName = "Standard_B1" +) + +func PossibleValuesForManagedHsmSkuName() []string { + return []string{ + string(ManagedHsmSkuNameCustomBSix), + string(ManagedHsmSkuNameCustomBThreeTwo), + string(ManagedHsmSkuNameCustomCFourTwo), + string(ManagedHsmSkuNameCustomCOneZero), + string(ManagedHsmSkuNameStandardBOne), + } +} + +func (s *ManagedHsmSkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuName(input string) (*ManagedHsmSkuName, error) { + vals := map[string]ManagedHsmSkuName{ + "custom_b6": ManagedHsmSkuNameCustomBSix, + "custom_b32": ManagedHsmSkuNameCustomBThreeTwo, + "custom_c42": ManagedHsmSkuNameCustomCFourTwo, + "custom_c10": ManagedHsmSkuNameCustomCOneZero, + "standard_b1": ManagedHsmSkuNameStandardBOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuName(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateDisconnected PrivateEndpointConnectionProvisioningState = "Disconnected" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateDisconnected), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + string(PrivateEndpointConnectionProvisioningStateUpdating), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "disconnected": PrivateEndpointConnectionProvisioningStateDisconnected, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + "updating": PrivateEndpointConnectionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusDisconnected PrivateEndpointServiceConnectionStatus = "Disconnected" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusDisconnected), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "disconnected": PrivateEndpointServiceConnectionStatusDisconnected, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm.go new file mode 100644 index 00000000000..d6cd800d486 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm.go @@ -0,0 +1,130 @@ +package mhsmlistprivateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedHSMId{}) +} + +var _ resourceids.ResourceId = &ManagedHSMId{} + +// ManagedHSMId is a struct representing the Resource ID for a Managed H S M +type ManagedHSMId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string +} + +// NewManagedHSMID returns a new ManagedHSMId struct +func NewManagedHSMID(subscriptionId string, resourceGroupName string, managedHSMName string) ManagedHSMId { + return ManagedHSMId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + } +} + +// ParseManagedHSMID parses 'input' into a ManagedHSMId +func ParseManagedHSMID(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedHSMIDInsensitively parses 'input' case-insensitively into a ManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseManagedHSMIDInsensitively(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + return nil +} + +// ValidateManagedHSMID checks that 'input' can be parsed as a Managed H S M ID +func ValidateManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed H S M ID +func (id ManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed H S M ID +func (id ManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + } +} + +// String returns a human-readable description of this Managed H S M ID +func (id ManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + } + return fmt.Sprintf("Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm_test.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm_test.go new file mode 100644 index 00000000000..0278e7c0b5c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/id_managedhsm_test.go @@ -0,0 +1,282 @@ +package mhsmlistprivateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedHSMId{} + +func TestNewManagedHSMID(t *testing.T) { + id := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } +} + +func TestFormatManagedHSMID(t *testing.T) { + actual := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestParseManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestSegmentsForManagedHSMId(t *testing.T) { + segments := ManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/method_mhsmprivateendpointconnectionslistbyresource.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/method_mhsmprivateendpointconnectionslistbyresource.go new file mode 100644 index 00000000000..c4d7fb3fc39 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/method_mhsmprivateendpointconnectionslistbyresource.go @@ -0,0 +1,105 @@ +package mhsmlistprivateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionsListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MHSMPrivateEndpointConnection +} + +type MHSMPrivateEndpointConnectionsListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []MHSMPrivateEndpointConnection +} + +type MHSMPrivateEndpointConnectionsListByResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MHSMPrivateEndpointConnectionsListByResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MHSMPrivateEndpointConnectionsListByResource ... +func (c MHSMListPrivateEndpointConnectionsClient) MHSMPrivateEndpointConnectionsListByResource(ctx context.Context, id ManagedHSMId) (result MHSMPrivateEndpointConnectionsListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &MHSMPrivateEndpointConnectionsListByResourceCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MHSMPrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MHSMPrivateEndpointConnectionsListByResourceComplete retrieves all the results into a single object +func (c MHSMListPrivateEndpointConnectionsClient) MHSMPrivateEndpointConnectionsListByResourceComplete(ctx context.Context, id ManagedHSMId) (MHSMPrivateEndpointConnectionsListByResourceCompleteResult, error) { + return c.MHSMPrivateEndpointConnectionsListByResourceCompleteMatchingPredicate(ctx, id, MHSMPrivateEndpointConnectionOperationPredicate{}) +} + +// MHSMPrivateEndpointConnectionsListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MHSMListPrivateEndpointConnectionsClient) MHSMPrivateEndpointConnectionsListByResourceCompleteMatchingPredicate(ctx context.Context, id ManagedHSMId, predicate MHSMPrivateEndpointConnectionOperationPredicate) (result MHSMPrivateEndpointConnectionsListByResourceCompleteResult, err error) { + items := make([]MHSMPrivateEndpointConnection, 0) + + resp, err := c.MHSMPrivateEndpointConnectionsListByResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MHSMPrivateEndpointConnectionsListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_managedhsmsku.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_managedhsmsku.go new file mode 100644 index 00000000000..80d6089af8f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_managedhsmsku.go @@ -0,0 +1,9 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmSku struct { + Family ManagedHsmSkuFamily `json:"family"` + Name ManagedHsmSkuName `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpoint.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpoint.go new file mode 100644 index 00000000000..584d7931ee7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpoint.go @@ -0,0 +1,8 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnection.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnection.go new file mode 100644 index 00000000000..a51b1b297c5 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnection.go @@ -0,0 +1,22 @@ +package mhsmlistprivateendpointconnections + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnection struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MHSMPrivateEndpointConnectionProperties `json:"properties,omitempty"` + Sku *ManagedHsmSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..983aa57e6bd --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionProperties struct { + PrivateEndpoint *MHSMPrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *MHSMPrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..3a7d8db5ebb --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/predicates.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/predicates.go new file mode 100644 index 00000000000..18e2f2156a7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/predicates.go @@ -0,0 +1,37 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p MHSMPrivateEndpointConnectionOperationPredicate) Matches(input MHSMPrivateEndpointConnection) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/version.go b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/version.go new file mode 100644 index 00000000000..9e677d2562a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistprivateendpointconnections/version.go @@ -0,0 +1,10 @@ +package mhsmlistprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/mhsmlistprivateendpointconnections/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/README.md b/resource-manager/keyvault/2024-11-01/mhsmlistregions/README.md new file mode 100644 index 00000000000..35bc501b131 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistregions` Documentation + +The `mhsmlistregions` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmlistregions" +``` + + +### Client Initialization + +```go +client := mhsmlistregions.NewMHSMListRegionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MHSMListRegionsClient.MHSMRegionsListByResource` + +```go +ctx := context.TODO() +id := mhsmlistregions.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +// alternatively `client.MHSMRegionsListByResource(ctx, id)` can be used to do batched pagination +items, err := client.MHSMRegionsListByResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/client.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/client.go new file mode 100644 index 00000000000..1c453687514 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/client.go @@ -0,0 +1,26 @@ +package mhsmlistregions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMListRegionsClient struct { + Client *resourcemanager.Client +} + +func NewMHSMListRegionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MHSMListRegionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "mhsmlistregions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MHSMListRegionsClient: %+v", err) + } + + return &MHSMListRegionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/constants.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/constants.go new file mode 100644 index 00000000000..1fb1987323b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/constants.go @@ -0,0 +1,63 @@ +package mhsmlistregions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoReplicationRegionProvisioningState string + +const ( + GeoReplicationRegionProvisioningStateCleanup GeoReplicationRegionProvisioningState = "Cleanup" + GeoReplicationRegionProvisioningStateDeleting GeoReplicationRegionProvisioningState = "Deleting" + GeoReplicationRegionProvisioningStateFailed GeoReplicationRegionProvisioningState = "Failed" + GeoReplicationRegionProvisioningStatePreprovisioning GeoReplicationRegionProvisioningState = "Preprovisioning" + GeoReplicationRegionProvisioningStateProvisioning GeoReplicationRegionProvisioningState = "Provisioning" + GeoReplicationRegionProvisioningStateSucceeded GeoReplicationRegionProvisioningState = "Succeeded" +) + +func PossibleValuesForGeoReplicationRegionProvisioningState() []string { + return []string{ + string(GeoReplicationRegionProvisioningStateCleanup), + string(GeoReplicationRegionProvisioningStateDeleting), + string(GeoReplicationRegionProvisioningStateFailed), + string(GeoReplicationRegionProvisioningStatePreprovisioning), + string(GeoReplicationRegionProvisioningStateProvisioning), + string(GeoReplicationRegionProvisioningStateSucceeded), + } +} + +func (s *GeoReplicationRegionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGeoReplicationRegionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGeoReplicationRegionProvisioningState(input string) (*GeoReplicationRegionProvisioningState, error) { + vals := map[string]GeoReplicationRegionProvisioningState{ + "cleanup": GeoReplicationRegionProvisioningStateCleanup, + "deleting": GeoReplicationRegionProvisioningStateDeleting, + "failed": GeoReplicationRegionProvisioningStateFailed, + "preprovisioning": GeoReplicationRegionProvisioningStatePreprovisioning, + "provisioning": GeoReplicationRegionProvisioningStateProvisioning, + "succeeded": GeoReplicationRegionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GeoReplicationRegionProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm.go new file mode 100644 index 00000000000..c0f864925b2 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm.go @@ -0,0 +1,130 @@ +package mhsmlistregions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedHSMId{}) +} + +var _ resourceids.ResourceId = &ManagedHSMId{} + +// ManagedHSMId is a struct representing the Resource ID for a Managed H S M +type ManagedHSMId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string +} + +// NewManagedHSMID returns a new ManagedHSMId struct +func NewManagedHSMID(subscriptionId string, resourceGroupName string, managedHSMName string) ManagedHSMId { + return ManagedHSMId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + } +} + +// ParseManagedHSMID parses 'input' into a ManagedHSMId +func ParseManagedHSMID(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedHSMIDInsensitively parses 'input' case-insensitively into a ManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseManagedHSMIDInsensitively(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + return nil +} + +// ValidateManagedHSMID checks that 'input' can be parsed as a Managed H S M ID +func ValidateManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed H S M ID +func (id ManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed H S M ID +func (id ManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + } +} + +// String returns a human-readable description of this Managed H S M ID +func (id ManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + } + return fmt.Sprintf("Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm_test.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm_test.go new file mode 100644 index 00000000000..7c2608304e9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/id_managedhsm_test.go @@ -0,0 +1,282 @@ +package mhsmlistregions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedHSMId{} + +func TestNewManagedHSMID(t *testing.T) { + id := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } +} + +func TestFormatManagedHSMID(t *testing.T) { + actual := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestParseManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestSegmentsForManagedHSMId(t *testing.T) { + segments := ManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/method_mhsmregionslistbyresource.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/method_mhsmregionslistbyresource.go new file mode 100644 index 00000000000..e8ac772dc0c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/method_mhsmregionslistbyresource.go @@ -0,0 +1,105 @@ +package mhsmlistregions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMRegionsListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MHSMGeoReplicatedRegion +} + +type MHSMRegionsListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []MHSMGeoReplicatedRegion +} + +type MHSMRegionsListByResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MHSMRegionsListByResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MHSMRegionsListByResource ... +func (c MHSMListRegionsClient) MHSMRegionsListByResource(ctx context.Context, id ManagedHSMId) (result MHSMRegionsListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &MHSMRegionsListByResourceCustomPager{}, + Path: fmt.Sprintf("%s/regions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MHSMGeoReplicatedRegion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MHSMRegionsListByResourceComplete retrieves all the results into a single object +func (c MHSMListRegionsClient) MHSMRegionsListByResourceComplete(ctx context.Context, id ManagedHSMId) (MHSMRegionsListByResourceCompleteResult, error) { + return c.MHSMRegionsListByResourceCompleteMatchingPredicate(ctx, id, MHSMGeoReplicatedRegionOperationPredicate{}) +} + +// MHSMRegionsListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MHSMListRegionsClient) MHSMRegionsListByResourceCompleteMatchingPredicate(ctx context.Context, id ManagedHSMId, predicate MHSMGeoReplicatedRegionOperationPredicate) (result MHSMRegionsListByResourceCompleteResult, err error) { + items := make([]MHSMGeoReplicatedRegion, 0) + + resp, err := c.MHSMRegionsListByResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MHSMRegionsListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/model_mhsmgeoreplicatedregion.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/model_mhsmgeoreplicatedregion.go new file mode 100644 index 00000000000..d585752c1e5 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/model_mhsmgeoreplicatedregion.go @@ -0,0 +1,10 @@ +package mhsmlistregions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMGeoReplicatedRegion struct { + IsPrimary *bool `json:"isPrimary,omitempty"` + Name *string `json:"name,omitempty"` + ProvisioningState *GeoReplicationRegionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/predicates.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/predicates.go new file mode 100644 index 00000000000..ae0da984504 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/predicates.go @@ -0,0 +1,22 @@ +package mhsmlistregions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMGeoReplicatedRegionOperationPredicate struct { + IsPrimary *bool + Name *string +} + +func (p MHSMGeoReplicatedRegionOperationPredicate) Matches(input MHSMGeoReplicatedRegion) bool { + + if p.IsPrimary != nil && (input.IsPrimary == nil || *p.IsPrimary != *input.IsPrimary) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmlistregions/version.go b/resource-manager/keyvault/2024-11-01/mhsmlistregions/version.go new file mode 100644 index 00000000000..61d8a940125 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmlistregions/version.go @@ -0,0 +1,10 @@ +package mhsmlistregions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/mhsmlistregions/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/README.md b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/README.md new file mode 100644 index 00000000000..fc6b4ce5d0b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/README.md @@ -0,0 +1,69 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections` Documentation + +The `mhsmprivateendpointconnections` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections" +``` + + +### Client Initialization + +```go +client := mhsmprivateendpointconnections.NewMHSMPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MHSMPrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := mhsmprivateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MHSMPrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := mhsmprivateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MHSMPrivateEndpointConnectionsClient.Put` + +```go +ctx := context.TODO() +id := mhsmprivateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "privateEndpointConnectionName") + +payload := mhsmprivateendpointconnections.MHSMPrivateEndpointConnection{ + // ... +} + + +read, err := client.Put(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/client.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/client.go new file mode 100644 index 00000000000..99b17fc2075 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/client.go @@ -0,0 +1,26 @@ +package mhsmprivateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewMHSMPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MHSMPrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "mhsmprivateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MHSMPrivateEndpointConnectionsClient: %+v", err) + } + + return &MHSMPrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/constants.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/constants.go new file mode 100644 index 00000000000..444ba4df0b7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/constants.go @@ -0,0 +1,239 @@ +package mhsmprivateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type ManagedHsmSkuFamily string + +const ( + ManagedHsmSkuFamilyB ManagedHsmSkuFamily = "B" + ManagedHsmSkuFamilyC ManagedHsmSkuFamily = "C" +) + +func PossibleValuesForManagedHsmSkuFamily() []string { + return []string{ + string(ManagedHsmSkuFamilyB), + string(ManagedHsmSkuFamilyC), + } +} + +func (s *ManagedHsmSkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuFamily(input string) (*ManagedHsmSkuFamily, error) { + vals := map[string]ManagedHsmSkuFamily{ + "b": ManagedHsmSkuFamilyB, + "c": ManagedHsmSkuFamilyC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuFamily(input) + return &out, nil +} + +type ManagedHsmSkuName string + +const ( + ManagedHsmSkuNameCustomBSix ManagedHsmSkuName = "Custom_B6" + ManagedHsmSkuNameCustomBThreeTwo ManagedHsmSkuName = "Custom_B32" + ManagedHsmSkuNameCustomCFourTwo ManagedHsmSkuName = "Custom_C42" + ManagedHsmSkuNameCustomCOneZero ManagedHsmSkuName = "Custom_C10" + ManagedHsmSkuNameStandardBOne ManagedHsmSkuName = "Standard_B1" +) + +func PossibleValuesForManagedHsmSkuName() []string { + return []string{ + string(ManagedHsmSkuNameCustomBSix), + string(ManagedHsmSkuNameCustomBThreeTwo), + string(ManagedHsmSkuNameCustomCFourTwo), + string(ManagedHsmSkuNameCustomCOneZero), + string(ManagedHsmSkuNameStandardBOne), + } +} + +func (s *ManagedHsmSkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuName(input string) (*ManagedHsmSkuName, error) { + vals := map[string]ManagedHsmSkuName{ + "custom_b6": ManagedHsmSkuNameCustomBSix, + "custom_b32": ManagedHsmSkuNameCustomBThreeTwo, + "custom_c42": ManagedHsmSkuNameCustomCFourTwo, + "custom_c10": ManagedHsmSkuNameCustomCOneZero, + "standard_b1": ManagedHsmSkuNameStandardBOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuName(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateDisconnected PrivateEndpointConnectionProvisioningState = "Disconnected" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateDisconnected), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + string(PrivateEndpointConnectionProvisioningStateUpdating), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "disconnected": PrivateEndpointConnectionProvisioningStateDisconnected, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + "updating": PrivateEndpointConnectionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusDisconnected PrivateEndpointServiceConnectionStatus = "Disconnected" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusDisconnected), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "disconnected": PrivateEndpointServiceConnectionStatusDisconnected, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..4a79649fb14 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package mhsmprivateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, managedHSMName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..4c384117c35 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package mhsmprivateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_delete.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_delete.go new file mode 100644 index 00000000000..9d597cdd570 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_delete.go @@ -0,0 +1,72 @@ +package mhsmprivateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MHSMPrivateEndpointConnection +} + +// Delete ... +func (c MHSMPrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c MHSMPrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_get.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_get.go new file mode 100644 index 00000000000..3894c9fde03 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package mhsmprivateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MHSMPrivateEndpointConnection +} + +// Get ... +func (c MHSMPrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MHSMPrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_put.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_put.go new file mode 100644 index 00000000000..fd0a8f9fa2d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/method_put.go @@ -0,0 +1,57 @@ +package mhsmprivateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MHSMPrivateEndpointConnection +} + +// Put ... +func (c MHSMPrivateEndpointConnectionsClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input MHSMPrivateEndpointConnection) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MHSMPrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_managedhsmsku.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_managedhsmsku.go new file mode 100644 index 00000000000..846aefa2cd9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_managedhsmsku.go @@ -0,0 +1,9 @@ +package mhsmprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmSku struct { + Family ManagedHsmSkuFamily `json:"family"` + Name ManagedHsmSkuName `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpoint.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpoint.go new file mode 100644 index 00000000000..efd7da80d73 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpoint.go @@ -0,0 +1,8 @@ +package mhsmprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnection.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnection.go new file mode 100644 index 00000000000..4772af6c56f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnection.go @@ -0,0 +1,22 @@ +package mhsmprivateendpointconnections + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnection struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MHSMPrivateEndpointConnectionProperties `json:"properties,omitempty"` + Sku *ManagedHsmSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..13ad3394c3e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package mhsmprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateEndpointConnectionProperties struct { + PrivateEndpoint *MHSMPrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *MHSMPrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..13353b33837 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/model_mhsmprivatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package mhsmprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/version.go b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/version.go new file mode 100644 index 00000000000..a70e490c746 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivateendpointconnections/version.go @@ -0,0 +1,10 @@ +package mhsmprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/mhsmprivateendpointconnections/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/README.md b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/README.md new file mode 100644 index 00000000000..95fd0b62ea6 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources` Documentation + +The `mhsmprivatelinkresources` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources" +``` + + +### Client Initialization + +```go +client := mhsmprivatelinkresources.NewMHSMPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MHSMPrivateLinkResourcesClient.ListByMHSMResource` + +```go +ctx := context.TODO() +id := mhsmprivatelinkresources.NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + +read, err := client.ListByMHSMResource(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/client.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/client.go new file mode 100644 index 00000000000..27d08cdc9b1 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/client.go @@ -0,0 +1,26 @@ +package mhsmprivatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewMHSMPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*MHSMPrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "mhsmprivatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MHSMPrivateLinkResourcesClient: %+v", err) + } + + return &MHSMPrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/constants.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/constants.go new file mode 100644 index 00000000000..bd6f45ad49b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/constants.go @@ -0,0 +1,101 @@ +package mhsmprivatelinkresources + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmSkuFamily string + +const ( + ManagedHsmSkuFamilyB ManagedHsmSkuFamily = "B" + ManagedHsmSkuFamilyC ManagedHsmSkuFamily = "C" +) + +func PossibleValuesForManagedHsmSkuFamily() []string { + return []string{ + string(ManagedHsmSkuFamilyB), + string(ManagedHsmSkuFamilyC), + } +} + +func (s *ManagedHsmSkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuFamily(input string) (*ManagedHsmSkuFamily, error) { + vals := map[string]ManagedHsmSkuFamily{ + "b": ManagedHsmSkuFamilyB, + "c": ManagedHsmSkuFamilyC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuFamily(input) + return &out, nil +} + +type ManagedHsmSkuName string + +const ( + ManagedHsmSkuNameCustomBSix ManagedHsmSkuName = "Custom_B6" + ManagedHsmSkuNameCustomBThreeTwo ManagedHsmSkuName = "Custom_B32" + ManagedHsmSkuNameCustomCFourTwo ManagedHsmSkuName = "Custom_C42" + ManagedHsmSkuNameCustomCOneZero ManagedHsmSkuName = "Custom_C10" + ManagedHsmSkuNameStandardBOne ManagedHsmSkuName = "Standard_B1" +) + +func PossibleValuesForManagedHsmSkuName() []string { + return []string{ + string(ManagedHsmSkuNameCustomBSix), + string(ManagedHsmSkuNameCustomBThreeTwo), + string(ManagedHsmSkuNameCustomCFourTwo), + string(ManagedHsmSkuNameCustomCOneZero), + string(ManagedHsmSkuNameStandardBOne), + } +} + +func (s *ManagedHsmSkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedHsmSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedHsmSkuName(input string) (*ManagedHsmSkuName, error) { + vals := map[string]ManagedHsmSkuName{ + "custom_b6": ManagedHsmSkuNameCustomBSix, + "custom_b32": ManagedHsmSkuNameCustomBThreeTwo, + "custom_c42": ManagedHsmSkuNameCustomCFourTwo, + "custom_c10": ManagedHsmSkuNameCustomCOneZero, + "standard_b1": ManagedHsmSkuNameStandardBOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedHsmSkuName(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm.go new file mode 100644 index 00000000000..0773a999e3d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm.go @@ -0,0 +1,130 @@ +package mhsmprivatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedHSMId{}) +} + +var _ resourceids.ResourceId = &ManagedHSMId{} + +// ManagedHSMId is a struct representing the Resource ID for a Managed H S M +type ManagedHSMId struct { + SubscriptionId string + ResourceGroupName string + ManagedHSMName string +} + +// NewManagedHSMID returns a new ManagedHSMId struct +func NewManagedHSMID(subscriptionId string, resourceGroupName string, managedHSMName string) ManagedHSMId { + return ManagedHSMId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedHSMName: managedHSMName, + } +} + +// ParseManagedHSMID parses 'input' into a ManagedHSMId +func ParseManagedHSMID(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedHSMIDInsensitively parses 'input' case-insensitively into a ManagedHSMId +// note: this method should only be used for API response data and not user input +func ParseManagedHSMIDInsensitively(input string) (*ManagedHSMId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedHSMId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedHSMId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedHSMId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ManagedHSMName, ok = input.Parsed["managedHSMName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedHSMName", input) + } + + return nil +} + +// ValidateManagedHSMID checks that 'input' can be parsed as a Managed H S M ID +func ValidateManagedHSMID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseManagedHSMID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed H S M ID +func (id ManagedHSMId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/managedHSMs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedHSMName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed H S M ID +func (id ManagedHSMId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticManagedHSMs", "managedHSMs", "managedHSMs"), + resourceids.UserSpecifiedSegment("managedHSMName", "managedHSMName"), + } +} + +// String returns a human-readable description of this Managed H S M ID +func (id ManagedHSMId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed H S M Name: %q", id.ManagedHSMName), + } + return fmt.Sprintf("Managed H S M (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm_test.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm_test.go new file mode 100644 index 00000000000..0afe45bdb8e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/id_managedhsm_test.go @@ -0,0 +1,282 @@ +package mhsmprivatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ManagedHSMId{} + +func TestNewManagedHSMID(t *testing.T) { + id := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedHSMName != "managedHSMName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedHSMName'", id.ManagedHSMName, "managedHSMName") + } +} + +func TestFormatManagedHSMID(t *testing.T) { + actual := NewManagedHSMID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedHSMName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedHSMID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestParseManagedHSMIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedHSMId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedHSMName: "managedHSMName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/managedHSMs/managedHSMName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE", + Expected: &ManagedHSMId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedHSMName: "mAnAgEdHsMnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/mAnAgEdHsMs/mAnAgEdHsMnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedHSMIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ManagedHSMName != v.Expected.ManagedHSMName { + t.Fatalf("Expected %q but got %q for ManagedHSMName", v.Expected.ManagedHSMName, actual.ManagedHSMName) + } + + } +} + +func TestSegmentsForManagedHSMId(t *testing.T) { + segments := ManagedHSMId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedHSMId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/method_listbymhsmresource.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/method_listbymhsmresource.go new file mode 100644 index 00000000000..b3faf90ed75 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/method_listbymhsmresource.go @@ -0,0 +1,54 @@ +package mhsmprivatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByMHSMResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MHSMPrivateLinkResourceListResult +} + +// ListByMHSMResource ... +func (c MHSMPrivateLinkResourcesClient) ListByMHSMResource(ctx context.Context, id ManagedHSMId) (result ListByMHSMResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MHSMPrivateLinkResourceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_managedhsmsku.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_managedhsmsku.go new file mode 100644 index 00000000000..31124d8e20f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_managedhsmsku.go @@ -0,0 +1,9 @@ +package mhsmprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedHsmSku struct { + Family ManagedHsmSkuFamily `json:"family"` + Name ManagedHsmSkuName `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresource.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresource.go new file mode 100644 index 00000000000..630d5c49daa --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresource.go @@ -0,0 +1,21 @@ +package mhsmprivatelinkresources + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MHSMPrivateLinkResourceProperties `json:"properties,omitempty"` + Sku *ManagedHsmSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourcelistresult.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourcelistresult.go new file mode 100644 index 00000000000..1589954fa56 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package mhsmprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkResourceListResult struct { + Value *[]MHSMPrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourceproperties.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourceproperties.go new file mode 100644 index 00000000000..318dc85b436 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/model_mhsmprivatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package mhsmprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MHSMPrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/version.go b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/version.go new file mode 100644 index 00000000000..936c8bb887f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/mhsmprivatelinkresources/version.go @@ -0,0 +1,10 @@ +package mhsmprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/mhsmprivatelinkresources/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/README.md b/resource-manager/keyvault/2024-11-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..1cf90cf5d08 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.ListByResource` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +// alternatively `client.ListByResource(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Put` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +read, err := client.Put(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/client.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/constants.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..fdeb29178f4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/constants.go @@ -0,0 +1,148 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateDisconnected PrivateEndpointConnectionProvisioningState = "Disconnected" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateDisconnected), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + string(PrivateEndpointConnectionProvisioningStateUpdating), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "disconnected": PrivateEndpointConnectionProvisioningStateDisconnected, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + "updating": PrivateEndpointConnectionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusDisconnected PrivateEndpointServiceConnectionStatus = "Disconnected" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusDisconnected), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "disconnected": PrivateEndpointServiceConnectionStatusDisconnected, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_delete.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..8bd4b0d8db4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_delete.go @@ -0,0 +1,73 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id commonids.KeyVaultPrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id commonids.KeyVaultPrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_get.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..858463234c2 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_get.go @@ -0,0 +1,55 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id commonids.KeyVaultPrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_listbyresource.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_listbyresource.go new file mode 100644 index 00000000000..a593ebd4593 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_listbyresource.go @@ -0,0 +1,106 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListByResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResource ... +func (c PrivateEndpointConnectionsClient) ListByResource(ctx context.Context, id commonids.KeyVaultId) (result ListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListByResourceComplete(ctx context.Context, id commonids.KeyVaultId) (ListByResourceCompleteResult, error) { + return c.ListByResourceCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListByResourceCompleteMatchingPredicate(ctx context.Context, id commonids.KeyVaultId, predicate PrivateEndpointConnectionOperationPredicate) (result ListByResourceCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.ListByResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_put.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_put.go new file mode 100644 index 00000000000..69e432545ca --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/method_put.go @@ -0,0 +1,58 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Put ... +func (c PrivateEndpointConnectionsClient) Put(ctx context.Context, id commonids.KeyVaultPrivateEndpointConnectionId, input PrivateEndpointConnection) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..74b0e5c4644 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,14 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..78e87db45fe --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ca71b62e3ff --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/predicates.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..accb20a0cc4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/predicates.go @@ -0,0 +1,37 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/privateendpointconnections/version.go b/resource-manager/keyvault/2024-11-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..2a7f8f118b4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/README.md b/resource-manager/keyvault/2024-11-01/privatelinkresources/README.md new file mode 100644 index 00000000000..ee7cfd569b4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByVault` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +read, err := client.ListByVault(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/client.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/method_listbyvault.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/method_listbyvault.go new file mode 100644 index 00000000000..1b2c4d5d6b8 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/method_listbyvault.go @@ -0,0 +1,55 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByVaultOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResourceListResult +} + +// ListByVault ... +func (c PrivateLinkResourcesClient) ListByVault(ctx context.Context, id commonids.KeyVaultId) (result ListByVaultOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResourceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..8bcc42fe6ee --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,13 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..fa950217c47 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/privatelinkresources/version.go b/resource-manager/keyvault/2024-11-01/privatelinkresources/version.go new file mode 100644 index 00000000000..115826b4920 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/README.md b/resource-manager/keyvault/2024-11-01/secrets/README.md new file mode 100644 index 00000000000..2a3883b99db --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/README.md @@ -0,0 +1,96 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/secrets` Documentation + +The `secrets` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/secrets" +``` + + +### Client Initialization + +```go +client := secrets.NewSecretsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecretsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "secretName") + +payload := secrets.SecretCreateOrUpdateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SecretsClient.Get` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "secretName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SecretsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +// alternatively `client.List(ctx, id, secrets.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, secrets.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SecretsClient.Update` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "secretName") + +payload := secrets.SecretPatchParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/secrets/client.go b/resource-manager/keyvault/2024-11-01/secrets/client.go new file mode 100644 index 00000000000..07a23983c45 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/client.go @@ -0,0 +1,26 @@ +package secrets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretsClient struct { + Client *resourcemanager.Client +} + +func NewSecretsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecretsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "secrets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecretsClient: %+v", err) + } + + return &SecretsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/id_secret.go b/resource-manager/keyvault/2024-11-01/secrets/id_secret.go new file mode 100644 index 00000000000..e6647f6fb78 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/id_secret.go @@ -0,0 +1,139 @@ +package secrets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SecretId{}) +} + +var _ resourceids.ResourceId = &SecretId{} + +// SecretId is a struct representing the Resource ID for a Secret +type SecretId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + SecretName string +} + +// NewSecretID returns a new SecretId struct +func NewSecretID(subscriptionId string, resourceGroupName string, vaultName string, secretName string) SecretId { + return SecretId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + SecretName: secretName, + } +} + +// ParseSecretID parses 'input' into a SecretId +func ParseSecretID(input string) (*SecretId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecretId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecretId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecretIDInsensitively parses 'input' case-insensitively into a SecretId +// note: this method should only be used for API response data and not user input +func ParseSecretIDInsensitively(input string) (*SecretId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecretId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecretId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecretId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.VaultName, ok = input.Parsed["vaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vaultName", input) + } + + if id.SecretName, ok = input.Parsed["secretName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "secretName", input) + } + + return nil +} + +// ValidateSecretID checks that 'input' can be parsed as a Secret ID +func ValidateSecretID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSecretID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Secret ID +func (id SecretId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/vaults/%s/secrets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.SecretName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Secret ID +func (id SecretId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultName"), + resourceids.StaticSegment("staticSecrets", "secrets", "secrets"), + resourceids.UserSpecifiedSegment("secretName", "secretName"), + } +} + +// String returns a human-readable description of this Secret ID +func (id SecretId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Secret Name: %q", id.SecretName), + } + return fmt.Sprintf("Secret (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/id_secret_test.go b/resource-manager/keyvault/2024-11-01/secrets/id_secret_test.go new file mode 100644 index 00000000000..d612c11a7a9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/id_secret_test.go @@ -0,0 +1,327 @@ +package secrets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SecretId{} + +func TestNewSecretID(t *testing.T) { + id := NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "secretName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.VaultName != "vaultName" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultName") + } + + if id.SecretName != "secretName" { + t.Fatalf("Expected %q but got %q for Segment 'SecretName'", id.SecretName, "secretName") + } +} + +func TestFormatSecretID(t *testing.T) { + actual := NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "secretName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets/secretName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecretID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecretId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets/secretName", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultName", + SecretName: "secretName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets/secretName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecretID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.SecretName != v.Expected.SecretName { + t.Fatalf("Expected %q but got %q for SecretName", v.Expected.SecretName, actual.SecretName) + } + + } +} + +func TestParseSecretIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecretId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/sEcReTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets/secretName", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultName", + SecretName: "secretName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/secrets/secretName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/sEcReTs/sEcReTnAmE", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtNaMe", + SecretName: "sEcReTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/sEcReTs/sEcReTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecretIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.SecretName != v.Expected.SecretName { + t.Fatalf("Expected %q but got %q for SecretName", v.Expected.SecretName, actual.SecretName) + } + + } +} + +func TestSegmentsForSecretId(t *testing.T) { + segments := SecretId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecretId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/method_createorupdate.go b/resource-manager/keyvault/2024-11-01/secrets/method_createorupdate.go new file mode 100644 index 00000000000..6dac5184eee --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/method_createorupdate.go @@ -0,0 +1,58 @@ +package secrets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Secret +} + +// CreateOrUpdate ... +func (c SecretsClient) CreateOrUpdate(ctx context.Context, id SecretId, input SecretCreateOrUpdateParameters) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Secret + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/method_get.go b/resource-manager/keyvault/2024-11-01/secrets/method_get.go new file mode 100644 index 00000000000..dd688babed6 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/method_get.go @@ -0,0 +1,53 @@ +package secrets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Secret +} + +// Get ... +func (c SecretsClient) Get(ctx context.Context, id SecretId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Secret + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/method_list.go b/resource-manager/keyvault/2024-11-01/secrets/method_list.go new file mode 100644 index 00000000000..4e8ea3e359e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/method_list.go @@ -0,0 +1,135 @@ +package secrets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Secret +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Secret +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c SecretsClient) List(ctx context.Context, id commonids.KeyVaultId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/secrets", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Secret `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecretsClient) ListComplete(ctx context.Context, id commonids.KeyVaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, SecretOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecretsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.KeyVaultId, options ListOperationOptions, predicate SecretOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Secret, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/method_update.go b/resource-manager/keyvault/2024-11-01/secrets/method_update.go new file mode 100644 index 00000000000..38bdcc04c5f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/method_update.go @@ -0,0 +1,58 @@ +package secrets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Secret +} + +// Update ... +func (c SecretsClient) Update(ctx context.Context, id SecretId, input SecretPatchParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Secret + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_attributes.go b/resource-manager/keyvault/2024-11-01/secrets/model_attributes.go new file mode 100644 index 00000000000..7f0df4ceec4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_attributes.go @@ -0,0 +1,12 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Attributes struct { + Created *int64 `json:"created,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Exp *int64 `json:"exp,omitempty"` + Nbf *int64 `json:"nbf,omitempty"` + Updated *int64 `json:"updated,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_secret.go b/resource-manager/keyvault/2024-11-01/secrets/model_secret.go new file mode 100644 index 00000000000..08ae4eaf41c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_secret.go @@ -0,0 +1,13 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Secret struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties SecretProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_secretcreateorupdateparameters.go b/resource-manager/keyvault/2024-11-01/secrets/model_secretcreateorupdateparameters.go new file mode 100644 index 00000000000..490bd25485b --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_secretcreateorupdateparameters.go @@ -0,0 +1,9 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretCreateOrUpdateParameters struct { + Properties SecretProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchparameters.go b/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchparameters.go new file mode 100644 index 00000000000..cb0d643f77a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchparameters.go @@ -0,0 +1,9 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretPatchParameters struct { + Properties *SecretPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchproperties.go b/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchproperties.go new file mode 100644 index 00000000000..d5fb8bddecf --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_secretpatchproperties.go @@ -0,0 +1,10 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretPatchProperties struct { + Attributes *Attributes `json:"attributes,omitempty"` + ContentType *string `json:"contentType,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/model_secretproperties.go b/resource-manager/keyvault/2024-11-01/secrets/model_secretproperties.go new file mode 100644 index 00000000000..a11f76f93b9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/model_secretproperties.go @@ -0,0 +1,12 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretProperties struct { + Attributes *Attributes `json:"attributes,omitempty"` + ContentType *string `json:"contentType,omitempty"` + SecretUri *string `json:"secretUri,omitempty"` + SecretUriWithVersion *string `json:"secretUriWithVersion,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/predicates.go b/resource-manager/keyvault/2024-11-01/secrets/predicates.go new file mode 100644 index 00000000000..1eb8d4feaa8 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/predicates.go @@ -0,0 +1,32 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SecretOperationPredicate) Matches(input Secret) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/secrets/version.go b/resource-manager/keyvault/2024-11-01/secrets/version.go new file mode 100644 index 00000000000..caf7f0c2fe2 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/secrets/version.go @@ -0,0 +1,10 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/secrets/2024-11-01" +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/README.md b/resource-manager/keyvault/2024-11-01/vaults/README.md new file mode 100644 index 00000000000..923fbb672a7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/README.md @@ -0,0 +1,229 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/vaults` Documentation + +The `vaults` SDK allows for interaction with Azure Resource Manager `keyvault` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2024-11-01/vaults" +``` + + +### Client Initialization + +```go +client := vaults.NewVaultsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VaultsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := vaults.VaultCheckNameAvailabilityParameters{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VaultsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +payload := vaults.VaultCreateOrUpdateParameters{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `VaultsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VaultsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VaultsClient.GetDeleted` + +```go +ctx := context.TODO() +id := vaults.NewDeletedVaultID("12345678-1234-9876-4563-123456789012", "locationName", "deletedVaultName") + +read, err := client.GetDeleted(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VaultsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, vaults.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, vaults.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `VaultsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, vaults.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, vaults.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `VaultsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, vaults.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, vaults.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `VaultsClient.ListDeleted` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListDeleted(ctx, id)` can be used to do batched pagination +items, err := client.ListDeletedComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `VaultsClient.PurgeDeleted` + +```go +ctx := context.TODO() +id := vaults.NewDeletedVaultID("12345678-1234-9876-4563-123456789012", "locationName", "deletedVaultName") + +if err := client.PurgeDeletedThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `VaultsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewKeyVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName") + +payload := vaults.VaultPatchParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VaultsClient.UpdateAccessPolicy` + +```go +ctx := context.TODO() +id := vaults.NewOperationKindID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "add") + +payload := vaults.VaultAccessPolicyParameters{ + // ... +} + + +read, err := client.UpdateAccessPolicy(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/keyvault/2024-11-01/vaults/client.go b/resource-manager/keyvault/2024-11-01/vaults/client.go new file mode 100644 index 00000000000..37bd7a44670 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/client.go @@ -0,0 +1,26 @@ +package vaults + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultsClient struct { + Client *resourcemanager.Client +} + +func NewVaultsClientWithBaseURI(sdkApi sdkEnv.Api) (*VaultsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "vaults", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VaultsClient: %+v", err) + } + + return &VaultsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/constants.go b/resource-manager/keyvault/2024-11-01/vaults/constants.go new file mode 100644 index 00000000000..a6d848aef64 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/constants.go @@ -0,0 +1,878 @@ +package vaults + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyUpdateKind string + +const ( + AccessPolicyUpdateKindAdd AccessPolicyUpdateKind = "add" + AccessPolicyUpdateKindRemove AccessPolicyUpdateKind = "remove" + AccessPolicyUpdateKindReplace AccessPolicyUpdateKind = "replace" +) + +func PossibleValuesForAccessPolicyUpdateKind() []string { + return []string{ + string(AccessPolicyUpdateKindAdd), + string(AccessPolicyUpdateKindRemove), + string(AccessPolicyUpdateKindReplace), + } +} + +func (s *AccessPolicyUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyUpdateKind(input string) (*AccessPolicyUpdateKind, error) { + vals := map[string]AccessPolicyUpdateKind{ + "add": AccessPolicyUpdateKindAdd, + "remove": AccessPolicyUpdateKindRemove, + "replace": AccessPolicyUpdateKindReplace, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyUpdateKind(input) + return &out, nil +} + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type CertificatePermissions string + +const ( + CertificatePermissionsAll CertificatePermissions = "all" + CertificatePermissionsBackup CertificatePermissions = "backup" + CertificatePermissionsCreate CertificatePermissions = "create" + CertificatePermissionsDelete CertificatePermissions = "delete" + CertificatePermissionsDeleteissuers CertificatePermissions = "deleteissuers" + CertificatePermissionsGet CertificatePermissions = "get" + CertificatePermissionsGetissuers CertificatePermissions = "getissuers" + CertificatePermissionsImport CertificatePermissions = "import" + CertificatePermissionsList CertificatePermissions = "list" + CertificatePermissionsListissuers CertificatePermissions = "listissuers" + CertificatePermissionsManagecontacts CertificatePermissions = "managecontacts" + CertificatePermissionsManageissuers CertificatePermissions = "manageissuers" + CertificatePermissionsPurge CertificatePermissions = "purge" + CertificatePermissionsRecover CertificatePermissions = "recover" + CertificatePermissionsRestore CertificatePermissions = "restore" + CertificatePermissionsSetissuers CertificatePermissions = "setissuers" + CertificatePermissionsUpdate CertificatePermissions = "update" +) + +func PossibleValuesForCertificatePermissions() []string { + return []string{ + string(CertificatePermissionsAll), + string(CertificatePermissionsBackup), + string(CertificatePermissionsCreate), + string(CertificatePermissionsDelete), + string(CertificatePermissionsDeleteissuers), + string(CertificatePermissionsGet), + string(CertificatePermissionsGetissuers), + string(CertificatePermissionsImport), + string(CertificatePermissionsList), + string(CertificatePermissionsListissuers), + string(CertificatePermissionsManagecontacts), + string(CertificatePermissionsManageissuers), + string(CertificatePermissionsPurge), + string(CertificatePermissionsRecover), + string(CertificatePermissionsRestore), + string(CertificatePermissionsSetissuers), + string(CertificatePermissionsUpdate), + } +} + +func (s *CertificatePermissions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificatePermissions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificatePermissions(input string) (*CertificatePermissions, error) { + vals := map[string]CertificatePermissions{ + "all": CertificatePermissionsAll, + "backup": CertificatePermissionsBackup, + "create": CertificatePermissionsCreate, + "delete": CertificatePermissionsDelete, + "deleteissuers": CertificatePermissionsDeleteissuers, + "get": CertificatePermissionsGet, + "getissuers": CertificatePermissionsGetissuers, + "import": CertificatePermissionsImport, + "list": CertificatePermissionsList, + "listissuers": CertificatePermissionsListissuers, + "managecontacts": CertificatePermissionsManagecontacts, + "manageissuers": CertificatePermissionsManageissuers, + "purge": CertificatePermissionsPurge, + "recover": CertificatePermissionsRecover, + "restore": CertificatePermissionsRestore, + "setissuers": CertificatePermissionsSetissuers, + "update": CertificatePermissionsUpdate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificatePermissions(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "default" + CreateModeRecover CreateMode = "recover" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeRecover), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "recover": CreateModeRecover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type KeyPermissions string + +const ( + KeyPermissionsAll KeyPermissions = "all" + KeyPermissionsBackup KeyPermissions = "backup" + KeyPermissionsCreate KeyPermissions = "create" + KeyPermissionsDecrypt KeyPermissions = "decrypt" + KeyPermissionsDelete KeyPermissions = "delete" + KeyPermissionsEncrypt KeyPermissions = "encrypt" + KeyPermissionsGet KeyPermissions = "get" + KeyPermissionsGetrotationpolicy KeyPermissions = "getrotationpolicy" + KeyPermissionsImport KeyPermissions = "import" + KeyPermissionsList KeyPermissions = "list" + KeyPermissionsPurge KeyPermissions = "purge" + KeyPermissionsRecover KeyPermissions = "recover" + KeyPermissionsRelease KeyPermissions = "release" + KeyPermissionsRestore KeyPermissions = "restore" + KeyPermissionsRotate KeyPermissions = "rotate" + KeyPermissionsSetrotationpolicy KeyPermissions = "setrotationpolicy" + KeyPermissionsSign KeyPermissions = "sign" + KeyPermissionsUnwrapKey KeyPermissions = "unwrapKey" + KeyPermissionsUpdate KeyPermissions = "update" + KeyPermissionsVerify KeyPermissions = "verify" + KeyPermissionsWrapKey KeyPermissions = "wrapKey" +) + +func PossibleValuesForKeyPermissions() []string { + return []string{ + string(KeyPermissionsAll), + string(KeyPermissionsBackup), + string(KeyPermissionsCreate), + string(KeyPermissionsDecrypt), + string(KeyPermissionsDelete), + string(KeyPermissionsEncrypt), + string(KeyPermissionsGet), + string(KeyPermissionsGetrotationpolicy), + string(KeyPermissionsImport), + string(KeyPermissionsList), + string(KeyPermissionsPurge), + string(KeyPermissionsRecover), + string(KeyPermissionsRelease), + string(KeyPermissionsRestore), + string(KeyPermissionsRotate), + string(KeyPermissionsSetrotationpolicy), + string(KeyPermissionsSign), + string(KeyPermissionsUnwrapKey), + string(KeyPermissionsUpdate), + string(KeyPermissionsVerify), + string(KeyPermissionsWrapKey), + } +} + +func (s *KeyPermissions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyPermissions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyPermissions(input string) (*KeyPermissions, error) { + vals := map[string]KeyPermissions{ + "all": KeyPermissionsAll, + "backup": KeyPermissionsBackup, + "create": KeyPermissionsCreate, + "decrypt": KeyPermissionsDecrypt, + "delete": KeyPermissionsDelete, + "encrypt": KeyPermissionsEncrypt, + "get": KeyPermissionsGet, + "getrotationpolicy": KeyPermissionsGetrotationpolicy, + "import": KeyPermissionsImport, + "list": KeyPermissionsList, + "purge": KeyPermissionsPurge, + "recover": KeyPermissionsRecover, + "release": KeyPermissionsRelease, + "restore": KeyPermissionsRestore, + "rotate": KeyPermissionsRotate, + "setrotationpolicy": KeyPermissionsSetrotationpolicy, + "sign": KeyPermissionsSign, + "unwrapkey": KeyPermissionsUnwrapKey, + "update": KeyPermissionsUpdate, + "verify": KeyPermissionsVerify, + "wrapkey": KeyPermissionsWrapKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyPermissions(input) + return &out, nil +} + +type NetworkRuleAction string + +const ( + NetworkRuleActionAllow NetworkRuleAction = "Allow" + NetworkRuleActionDeny NetworkRuleAction = "Deny" +) + +func PossibleValuesForNetworkRuleAction() []string { + return []string{ + string(NetworkRuleActionAllow), + string(NetworkRuleActionDeny), + } +} + +func (s *NetworkRuleAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleAction(input string) (*NetworkRuleAction, error) { + vals := map[string]NetworkRuleAction{ + "allow": NetworkRuleActionAllow, + "deny": NetworkRuleActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleAction(input) + return &out, nil +} + +type NetworkRuleBypassOptions string + +const ( + NetworkRuleBypassOptionsAzureServices NetworkRuleBypassOptions = "AzureServices" + NetworkRuleBypassOptionsNone NetworkRuleBypassOptions = "None" +) + +func PossibleValuesForNetworkRuleBypassOptions() []string { + return []string{ + string(NetworkRuleBypassOptionsAzureServices), + string(NetworkRuleBypassOptionsNone), + } +} + +func (s *NetworkRuleBypassOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleBypassOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleBypassOptions(input string) (*NetworkRuleBypassOptions, error) { + vals := map[string]NetworkRuleBypassOptions{ + "azureservices": NetworkRuleBypassOptionsAzureServices, + "none": NetworkRuleBypassOptionsNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleBypassOptions(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateDisconnected PrivateEndpointConnectionProvisioningState = "Disconnected" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" + PrivateEndpointConnectionProvisioningStateUpdating PrivateEndpointConnectionProvisioningState = "Updating" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateDisconnected), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + string(PrivateEndpointConnectionProvisioningStateUpdating), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "disconnected": PrivateEndpointConnectionProvisioningStateDisconnected, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + "updating": PrivateEndpointConnectionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusDisconnected PrivateEndpointServiceConnectionStatus = "Disconnected" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusDisconnected), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "disconnected": PrivateEndpointServiceConnectionStatusDisconnected, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type Reason string + +const ( + ReasonAccountNameInvalid Reason = "AccountNameInvalid" + ReasonAlreadyExists Reason = "AlreadyExists" +) + +func PossibleValuesForReason() []string { + return []string{ + string(ReasonAccountNameInvalid), + string(ReasonAlreadyExists), + } +} + +func (s *Reason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReason(input string) (*Reason, error) { + vals := map[string]Reason{ + "accountnameinvalid": ReasonAccountNameInvalid, + "alreadyexists": ReasonAlreadyExists, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Reason(input) + return &out, nil +} + +type SecretPermissions string + +const ( + SecretPermissionsAll SecretPermissions = "all" + SecretPermissionsBackup SecretPermissions = "backup" + SecretPermissionsDelete SecretPermissions = "delete" + SecretPermissionsGet SecretPermissions = "get" + SecretPermissionsList SecretPermissions = "list" + SecretPermissionsPurge SecretPermissions = "purge" + SecretPermissionsRecover SecretPermissions = "recover" + SecretPermissionsRestore SecretPermissions = "restore" + SecretPermissionsSet SecretPermissions = "set" +) + +func PossibleValuesForSecretPermissions() []string { + return []string{ + string(SecretPermissionsAll), + string(SecretPermissionsBackup), + string(SecretPermissionsDelete), + string(SecretPermissionsGet), + string(SecretPermissionsList), + string(SecretPermissionsPurge), + string(SecretPermissionsRecover), + string(SecretPermissionsRestore), + string(SecretPermissionsSet), + } +} + +func (s *SecretPermissions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretPermissions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretPermissions(input string) (*SecretPermissions, error) { + vals := map[string]SecretPermissions{ + "all": SecretPermissionsAll, + "backup": SecretPermissionsBackup, + "delete": SecretPermissionsDelete, + "get": SecretPermissionsGet, + "list": SecretPermissionsList, + "purge": SecretPermissionsPurge, + "recover": SecretPermissionsRecover, + "restore": SecretPermissionsRestore, + "set": SecretPermissionsSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretPermissions(input) + return &out, nil +} + +type SkuFamily string + +const ( + SkuFamilyA SkuFamily = "A" +) + +func PossibleValuesForSkuFamily() []string { + return []string{ + string(SkuFamilyA), + } +} + +func (s *SkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuFamily(input string) (*SkuFamily, error) { + vals := map[string]SkuFamily{ + "a": SkuFamilyA, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuFamily(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNamePremium SkuName = "premium" + SkuNameStandard SkuName = "standard" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNamePremium), + string(SkuNameStandard), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "premium": SkuNamePremium, + "standard": SkuNameStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type StoragePermissions string + +const ( + StoragePermissionsAll StoragePermissions = "all" + StoragePermissionsBackup StoragePermissions = "backup" + StoragePermissionsDelete StoragePermissions = "delete" + StoragePermissionsDeletesas StoragePermissions = "deletesas" + StoragePermissionsGet StoragePermissions = "get" + StoragePermissionsGetsas StoragePermissions = "getsas" + StoragePermissionsList StoragePermissions = "list" + StoragePermissionsListsas StoragePermissions = "listsas" + StoragePermissionsPurge StoragePermissions = "purge" + StoragePermissionsRecover StoragePermissions = "recover" + StoragePermissionsRegeneratekey StoragePermissions = "regeneratekey" + StoragePermissionsRestore StoragePermissions = "restore" + StoragePermissionsSet StoragePermissions = "set" + StoragePermissionsSetsas StoragePermissions = "setsas" + StoragePermissionsUpdate StoragePermissions = "update" +) + +func PossibleValuesForStoragePermissions() []string { + return []string{ + string(StoragePermissionsAll), + string(StoragePermissionsBackup), + string(StoragePermissionsDelete), + string(StoragePermissionsDeletesas), + string(StoragePermissionsGet), + string(StoragePermissionsGetsas), + string(StoragePermissionsList), + string(StoragePermissionsListsas), + string(StoragePermissionsPurge), + string(StoragePermissionsRecover), + string(StoragePermissionsRegeneratekey), + string(StoragePermissionsRestore), + string(StoragePermissionsSet), + string(StoragePermissionsSetsas), + string(StoragePermissionsUpdate), + } +} + +func (s *StoragePermissions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStoragePermissions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStoragePermissions(input string) (*StoragePermissions, error) { + vals := map[string]StoragePermissions{ + "all": StoragePermissionsAll, + "backup": StoragePermissionsBackup, + "delete": StoragePermissionsDelete, + "deletesas": StoragePermissionsDeletesas, + "get": StoragePermissionsGet, + "getsas": StoragePermissionsGetsas, + "list": StoragePermissionsList, + "listsas": StoragePermissionsListsas, + "purge": StoragePermissionsPurge, + "recover": StoragePermissionsRecover, + "regeneratekey": StoragePermissionsRegeneratekey, + "restore": StoragePermissionsRestore, + "set": StoragePermissionsSet, + "setsas": StoragePermissionsSetsas, + "update": StoragePermissionsUpdate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StoragePermissions(input) + return &out, nil +} + +type Type string + +const ( + TypeMicrosoftPointKeyVaultVaults Type = "Microsoft.KeyVault/vaults" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeMicrosoftPointKeyVaultVaults), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "microsoft.keyvault/vaults": TypeMicrosoftPointKeyVaultVaults, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} + +type VaultListFilterTypes string + +const ( + VaultListFilterTypesResourceTypeEqMicrosoftPointKeyVaultVaults VaultListFilterTypes = "resourceType eq 'Microsoft.KeyVault/vaults'" +) + +func PossibleValuesForVaultListFilterTypes() []string { + return []string{ + string(VaultListFilterTypesResourceTypeEqMicrosoftPointKeyVaultVaults), + } +} + +func (s *VaultListFilterTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVaultListFilterTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVaultListFilterTypes(input string) (*VaultListFilterTypes, error) { + vals := map[string]VaultListFilterTypes{ + "resourcetype eq 'microsoft.keyvault/vaults'": VaultListFilterTypesResourceTypeEqMicrosoftPointKeyVaultVaults, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VaultListFilterTypes(input) + return &out, nil +} + +type VaultProvisioningState string + +const ( + VaultProvisioningStateRegisteringDns VaultProvisioningState = "RegisteringDns" + VaultProvisioningStateSucceeded VaultProvisioningState = "Succeeded" +) + +func PossibleValuesForVaultProvisioningState() []string { + return []string{ + string(VaultProvisioningStateRegisteringDns), + string(VaultProvisioningStateSucceeded), + } +} + +func (s *VaultProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVaultProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVaultProvisioningState(input string) (*VaultProvisioningState, error) { + vals := map[string]VaultProvisioningState{ + "registeringdns": VaultProvisioningStateRegisteringDns, + "succeeded": VaultProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VaultProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault.go b/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault.go new file mode 100644 index 00000000000..f9769000e5d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault.go @@ -0,0 +1,130 @@ +package vaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeletedVaultId{}) +} + +var _ resourceids.ResourceId = &DeletedVaultId{} + +// DeletedVaultId is a struct representing the Resource ID for a Deleted Vault +type DeletedVaultId struct { + SubscriptionId string + LocationName string + DeletedVaultName string +} + +// NewDeletedVaultID returns a new DeletedVaultId struct +func NewDeletedVaultID(subscriptionId string, locationName string, deletedVaultName string) DeletedVaultId { + return DeletedVaultId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + DeletedVaultName: deletedVaultName, + } +} + +// ParseDeletedVaultID parses 'input' into a DeletedVaultId +func ParseDeletedVaultID(input string) (*DeletedVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedVaultIDInsensitively parses 'input' case-insensitively into a DeletedVaultId +// note: this method should only be used for API response data and not user input +func ParseDeletedVaultIDInsensitively(input string) (*DeletedVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedVaultId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.DeletedVaultName, ok = input.Parsed["deletedVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedVaultName", input) + } + + return nil +} + +// ValidateDeletedVaultID checks that 'input' can be parsed as a Deleted Vault ID +func ValidateDeletedVaultID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDeletedVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Vault ID +func (id DeletedVaultId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.KeyVault/locations/%s/deletedVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.DeletedVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Vault ID +func (id DeletedVaultId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticDeletedVaults", "deletedVaults", "deletedVaults"), + resourceids.UserSpecifiedSegment("deletedVaultName", "deletedVaultName"), + } +} + +// String returns a human-readable description of this Deleted Vault ID +func (id DeletedVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Deleted Vault Name: %q", id.DeletedVaultName), + } + return fmt.Sprintf("Deleted Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault_test.go b/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault_test.go new file mode 100644 index 00000000000..10ca0ba01ad --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/id_deletedvault_test.go @@ -0,0 +1,282 @@ +package vaults + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DeletedVaultId{} + +func TestNewDeletedVaultID(t *testing.T) { + id := NewDeletedVaultID("12345678-1234-9876-4563-123456789012", "locationName", "deletedVaultName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.DeletedVaultName != "deletedVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedVaultName'", id.DeletedVaultName, "deletedVaultName") + } +} + +func TestFormatDeletedVaultID(t *testing.T) { + actual := NewDeletedVaultID("12345678-1234-9876-4563-123456789012", "locationName", "deletedVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults/deletedVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedVaultId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults/deletedVaultName", + Expected: &DeletedVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedVaultName: "deletedVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults/deletedVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedVaultID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedVaultName != v.Expected.DeletedVaultName { + t.Fatalf("Expected %q but got %q for DeletedVaultName", v.Expected.DeletedVaultName, actual.DeletedVaultName) + } + + } +} + +func TestParseDeletedVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedVaultId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdVaUlTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults/deletedVaultName", + Expected: &DeletedVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedVaultName: "deletedVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.KeyVault/locations/locationName/deletedVaults/deletedVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdVaUlTs/dElEtEdVaUlTnAmE", + Expected: &DeletedVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + DeletedVaultName: "dElEtEdVaUlTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.kEyVaUlT/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdVaUlTs/dElEtEdVaUlTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedVaultIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedVaultName != v.Expected.DeletedVaultName { + t.Fatalf("Expected %q but got %q for DeletedVaultName", v.Expected.DeletedVaultName, actual.DeletedVaultName) + } + + } +} + +func TestSegmentsForDeletedVaultId(t *testing.T) { + segments := DeletedVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedVaultId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/id_operationkind.go b/resource-manager/keyvault/2024-11-01/vaults/id_operationkind.go new file mode 100644 index 00000000000..e7a7dc4fc14 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/id_operationkind.go @@ -0,0 +1,147 @@ +package vaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationKindId{}) +} + +var _ resourceids.ResourceId = &OperationKindId{} + +// OperationKindId is a struct representing the Resource ID for a Operation Kind +type OperationKindId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + OperationKind AccessPolicyUpdateKind +} + +// NewOperationKindID returns a new OperationKindId struct +func NewOperationKindID(subscriptionId string, resourceGroupName string, vaultName string, operationKind AccessPolicyUpdateKind) OperationKindId { + return OperationKindId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + OperationKind: operationKind, + } +} + +// ParseOperationKindID parses 'input' into a OperationKindId +func ParseOperationKindID(input string) (*OperationKindId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationKindId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationKindId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationKindIDInsensitively parses 'input' case-insensitively into a OperationKindId +// note: this method should only be used for API response data and not user input +func ParseOperationKindIDInsensitively(input string) (*OperationKindId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationKindId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationKindId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationKindId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.VaultName, ok = input.Parsed["vaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "vaultName", input) + } + + if v, ok := input.Parsed["operationKind"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationKind", input) + } + + operationKind, err := parseAccessPolicyUpdateKind(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.OperationKind = *operationKind + } + + return nil +} + +// ValidateOperationKindID checks that 'input' can be parsed as a Operation Kind ID +func ValidateOperationKindID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationKindID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation Kind ID +func (id OperationKindId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.KeyVault/vaults/%s/accessPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, string(id.OperationKind)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation Kind ID +func (id OperationKindId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKeyVault", "Microsoft.KeyVault", "Microsoft.KeyVault"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultName"), + resourceids.StaticSegment("staticAccessPolicies", "accessPolicies", "accessPolicies"), + resourceids.ConstantSegment("operationKind", PossibleValuesForAccessPolicyUpdateKind(), "add"), + } +} + +// String returns a human-readable description of this Operation Kind ID +func (id OperationKindId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Operation Kind: %q", string(id.OperationKind)), + } + return fmt.Sprintf("Operation Kind (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/id_operationkind_test.go b/resource-manager/keyvault/2024-11-01/vaults/id_operationkind_test.go new file mode 100644 index 00000000000..2bd1ee70322 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/id_operationkind_test.go @@ -0,0 +1,327 @@ +package vaults + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationKindId{} + +func TestNewOperationKindID(t *testing.T) { + id := NewOperationKindID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "add") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.VaultName != "vaultName" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultName") + } + + if id.OperationKind != "add" { + t.Fatalf("Expected %q but got %q for Segment 'OperationKind'", id.OperationKind, "add") + } +} + +func TestFormatOperationKindID(t *testing.T) { + actual := NewOperationKindID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultName", "add").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies/add" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationKindID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationKindId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies/add", + Expected: &OperationKindId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultName", + OperationKind: "add", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies/add/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationKindID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.OperationKind != v.Expected.OperationKind { + t.Fatalf("Expected %q but got %q for OperationKind", v.Expected.OperationKind, actual.OperationKind) + } + + } +} + +func TestParseOperationKindIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationKindId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/aCcEsSpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies/add", + Expected: &OperationKindId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultName", + OperationKind: "add", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.KeyVault/vaults/vaultName/accessPolicies/add/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/aCcEsSpOlIcIeS/aDd", + Expected: &OperationKindId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtNaMe", + OperationKind: "add", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kEyVaUlT/vAuLtS/vAuLtNaMe/aCcEsSpOlIcIeS/aDd/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationKindIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.OperationKind != v.Expected.OperationKind { + t.Fatalf("Expected %q but got %q for OperationKind", v.Expected.OperationKind, actual.OperationKind) + } + + } +} + +func TestSegmentsForOperationKindId(t *testing.T) { + segments := OperationKindId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationKindId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_checknameavailability.go b/resource-manager/keyvault/2024-11-01/vaults/method_checknameavailability.go new file mode 100644 index 00000000000..7c7a6ee9312 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_checknameavailability.go @@ -0,0 +1,59 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResult +} + +// CheckNameAvailability ... +func (c VaultsClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input VaultCheckNameAvailabilityParameters) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_createorupdate.go b/resource-manager/keyvault/2024-11-01/vaults/method_createorupdate.go new file mode 100644 index 00000000000..1c7d4cb2500 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_createorupdate.go @@ -0,0 +1,76 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Vault +} + +// CreateOrUpdate ... +func (c VaultsClient) CreateOrUpdate(ctx context.Context, id commonids.KeyVaultId, input VaultCreateOrUpdateParameters) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c VaultsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.KeyVaultId, input VaultCreateOrUpdateParameters) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_delete.go b/resource-manager/keyvault/2024-11-01/vaults/method_delete.go new file mode 100644 index 00000000000..8875d26814e --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_delete.go @@ -0,0 +1,48 @@ +package vaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c VaultsClient) Delete(ctx context.Context, id commonids.KeyVaultId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_get.go b/resource-manager/keyvault/2024-11-01/vaults/method_get.go new file mode 100644 index 00000000000..2b39e261b71 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_get.go @@ -0,0 +1,54 @@ +package vaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Vault +} + +// Get ... +func (c VaultsClient) Get(ctx context.Context, id commonids.KeyVaultId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Vault + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_getdeleted.go b/resource-manager/keyvault/2024-11-01/vaults/method_getdeleted.go new file mode 100644 index 00000000000..3d8e1856e62 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_getdeleted.go @@ -0,0 +1,53 @@ +package vaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetDeletedOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeletedVault +} + +// GetDeleted ... +func (c VaultsClient) GetDeleted(ctx context.Context, id DeletedVaultId) (result GetDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DeletedVault + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_list.go b/resource-manager/keyvault/2024-11-01/vaults/method_list.go new file mode 100644 index 00000000000..539855f32ba --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_list.go @@ -0,0 +1,139 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListOperationOptions struct { + Filter *VaultListFilterTypes + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c VaultsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/resources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c VaultsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VaultsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_listbyresourcegroup.go b/resource-manager/keyvault/2024-11-01/vaults/method_listbyresourcegroup.go new file mode 100644 index 00000000000..db6ebff4bae --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_listbyresourcegroup.go @@ -0,0 +1,135 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Vault +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Vault +} + +type ListByResourceGroupOperationOptions struct { + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c VaultsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/vaults", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Vault `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c VaultsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, VaultOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VaultsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate VaultOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Vault, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_listbysubscription.go b/resource-manager/keyvault/2024-11-01/vaults/method_listbysubscription.go new file mode 100644 index 00000000000..a2d216fea2f --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_listbysubscription.go @@ -0,0 +1,135 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Vault +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Vault +} + +type ListBySubscriptionOperationOptions struct { + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c VaultsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/vaults", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Vault `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c VaultsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, VaultOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VaultsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate VaultOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Vault, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_listdeleted.go b/resource-manager/keyvault/2024-11-01/vaults/method_listdeleted.go new file mode 100644 index 00000000000..be4737ce398 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_listdeleted.go @@ -0,0 +1,106 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListDeletedOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeletedVault +} + +type ListDeletedCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedVault +} + +type ListDeletedCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListDeletedCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListDeleted ... +func (c VaultsClient) ListDeleted(ctx context.Context, id commonids.SubscriptionId) (result ListDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListDeletedCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.KeyVault/deletedVaults", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DeletedVault `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListDeletedComplete retrieves all the results into a single object +func (c VaultsClient) ListDeletedComplete(ctx context.Context, id commonids.SubscriptionId) (ListDeletedCompleteResult, error) { + return c.ListDeletedCompleteMatchingPredicate(ctx, id, DeletedVaultOperationPredicate{}) +} + +// ListDeletedCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VaultsClient) ListDeletedCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DeletedVaultOperationPredicate) (result ListDeletedCompleteResult, err error) { + items := make([]DeletedVault, 0) + + resp, err := c.ListDeleted(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListDeletedCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_purgedeleted.go b/resource-manager/keyvault/2024-11-01/vaults/method_purgedeleted.go new file mode 100644 index 00000000000..11fc0e8e4e8 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_purgedeleted.go @@ -0,0 +1,70 @@ +package vaults + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeDeletedOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PurgeDeleted ... +func (c VaultsClient) PurgeDeleted(ctx context.Context, id DeletedVaultId) (result PurgeDeletedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/purge", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PurgeDeletedThenPoll performs PurgeDeleted then polls until it's completed +func (c VaultsClient) PurgeDeletedThenPoll(ctx context.Context, id DeletedVaultId) error { + result, err := c.PurgeDeleted(ctx, id) + if err != nil { + return fmt.Errorf("performing PurgeDeleted: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PurgeDeleted: %+v", err) + } + + return nil +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_update.go b/resource-manager/keyvault/2024-11-01/vaults/method_update.go new file mode 100644 index 00000000000..132468e7ca3 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_update.go @@ -0,0 +1,59 @@ +package vaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Vault +} + +// Update ... +func (c VaultsClient) Update(ctx context.Context, id commonids.KeyVaultId, input VaultPatchParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Vault + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/method_updateaccesspolicy.go b/resource-manager/keyvault/2024-11-01/vaults/method_updateaccesspolicy.go new file mode 100644 index 00000000000..7625f00ba01 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/method_updateaccesspolicy.go @@ -0,0 +1,58 @@ +package vaults + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateAccessPolicyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VaultAccessPolicyParameters +} + +// UpdateAccessPolicy ... +func (c VaultsClient) UpdateAccessPolicy(ctx context.Context, id OperationKindId, input VaultAccessPolicyParameters) (result UpdateAccessPolicyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model VaultAccessPolicyParameters + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_accesspolicyentry.go b/resource-manager/keyvault/2024-11-01/vaults/model_accesspolicyentry.go new file mode 100644 index 00000000000..a183e1481b6 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_accesspolicyentry.go @@ -0,0 +1,11 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyEntry struct { + ApplicationId *string `json:"applicationId,omitempty"` + ObjectId string `json:"objectId"` + Permissions Permissions `json:"permissions"` + TenantId string `json:"tenantId"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_checknameavailabilityresult.go b/resource-manager/keyvault/2024-11-01/vaults/model_checknameavailabilityresult.go new file mode 100644 index 00000000000..392070c655a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_checknameavailabilityresult.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResult struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *Reason `json:"reason,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_deletedvault.go b/resource-manager/keyvault/2024-11-01/vaults/model_deletedvault.go new file mode 100644 index 00000000000..0516f7fabdc --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_deletedvault.go @@ -0,0 +1,11 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedVault struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedVaultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_deletedvaultproperties.go b/resource-manager/keyvault/2024-11-01/vaults/model_deletedvaultproperties.go new file mode 100644 index 00000000000..e8857532e44 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_deletedvaultproperties.go @@ -0,0 +1,43 @@ +package vaults + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedVaultProperties struct { + DeletionDate *string `json:"deletionDate,omitempty"` + Location *string `json:"location,omitempty"` + PurgeProtectionEnabled *bool `json:"purgeProtectionEnabled,omitempty"` + ScheduledPurgeDate *string `json:"scheduledPurgeDate,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + VaultId *string `json:"vaultId,omitempty"` +} + +func (o *DeletedVaultProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedVaultProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *DeletedVaultProperties) GetScheduledPurgeDateAsTime() (*time.Time, error) { + if o.ScheduledPurgeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduledPurgeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedVaultProperties) SetScheduledPurgeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduledPurgeDate = &formatted +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_iprule.go b/resource-manager/keyvault/2024-11-01/vaults/model_iprule.go new file mode 100644 index 00000000000..1ef577d7d01 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_iprule.go @@ -0,0 +1,8 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPRule struct { + Value string `json:"value"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_networkruleset.go b/resource-manager/keyvault/2024-11-01/vaults/model_networkruleset.go new file mode 100644 index 00000000000..044635c0f77 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_networkruleset.go @@ -0,0 +1,11 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkRuleSet struct { + Bypass *NetworkRuleBypassOptions `json:"bypass,omitempty"` + DefaultAction *NetworkRuleAction `json:"defaultAction,omitempty"` + IPRules *[]IPRule `json:"ipRules,omitempty"` + VirtualNetworkRules *[]VirtualNetworkRule `json:"virtualNetworkRules,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_permissions.go b/resource-manager/keyvault/2024-11-01/vaults/model_permissions.go new file mode 100644 index 00000000000..b5f9cca4bd6 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_permissions.go @@ -0,0 +1,11 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Permissions struct { + Certificates *[]CertificatePermissions `json:"certificates,omitempty"` + Keys *[]KeyPermissions `json:"keys,omitempty"` + Secrets *[]SecretPermissions `json:"secrets,omitempty"` + Storage *[]StoragePermissions `json:"storage,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_privateendpoint.go b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpoint.go new file mode 100644 index 00000000000..64ce35a3d98 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpoint.go @@ -0,0 +1,8 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionitem.go b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionitem.go new file mode 100644 index 00000000000..a0f6df8359d --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionitem.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionItem struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionproperties.go b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..7dd15bb6220 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_privatelinkserviceconnectionstate.go b/resource-manager/keyvault/2024-11-01/vaults/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ced73fba28c --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_resource.go b/resource-manager/keyvault/2024-11-01/vaults/model_resource.go new file mode 100644 index 00000000000..2c29e958d53 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_resource.go @@ -0,0 +1,12 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_sku.go b/resource-manager/keyvault/2024-11-01/vaults/model_sku.go new file mode 100644 index 00000000000..259dd1fce3a --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_sku.go @@ -0,0 +1,9 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Family SkuFamily `json:"family"` + Name SkuName `json:"name"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vault.go b/resource-manager/keyvault/2024-11-01/vaults/model_vault.go new file mode 100644 index 00000000000..cfb5acec999 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vault.go @@ -0,0 +1,18 @@ +package vaults + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Vault struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties VaultProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyparameters.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyparameters.go new file mode 100644 index 00000000000..7353ce39d54 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyparameters.go @@ -0,0 +1,12 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultAccessPolicyParameters struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties VaultAccessPolicyProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyproperties.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyproperties.go new file mode 100644 index 00000000000..78525492fd7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultaccesspolicyproperties.go @@ -0,0 +1,8 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultAccessPolicyProperties struct { + AccessPolicies []AccessPolicyEntry `json:"accessPolicies"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultchecknameavailabilityparameters.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultchecknameavailabilityparameters.go new file mode 100644 index 00000000000..b9f9c94d368 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultchecknameavailabilityparameters.go @@ -0,0 +1,9 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultCheckNameAvailabilityParameters struct { + Name string `json:"name"` + Type Type `json:"type"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultcreateorupdateparameters.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultcreateorupdateparameters.go new file mode 100644 index 00000000000..6e8ca68bd73 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultcreateorupdateparameters.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultCreateOrUpdateParameters struct { + Location string `json:"location"` + Properties VaultProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchparameters.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchparameters.go new file mode 100644 index 00000000000..9352a604c87 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchparameters.go @@ -0,0 +1,9 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultPatchParameters struct { + Properties *VaultPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchproperties.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchproperties.go new file mode 100644 index 00000000000..9a4f85f22a4 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultpatchproperties.go @@ -0,0 +1,20 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultPatchProperties struct { + AccessPolicies *[]AccessPolicyEntry `json:"accessPolicies,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + EnablePurgeProtection *bool `json:"enablePurgeProtection,omitempty"` + EnableRbacAuthorization *bool `json:"enableRbacAuthorization,omitempty"` + EnableSoftDelete *bool `json:"enableSoftDelete,omitempty"` + EnabledForDeployment *bool `json:"enabledForDeployment,omitempty"` + EnabledForDiskEncryption *bool `json:"enabledForDiskEncryption,omitempty"` + EnabledForTemplateDeployment *bool `json:"enabledForTemplateDeployment,omitempty"` + NetworkAcls *NetworkRuleSet `json:"networkAcls,omitempty"` + PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SoftDeleteRetentionInDays *int64 `json:"softDeleteRetentionInDays,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_vaultproperties.go b/resource-manager/keyvault/2024-11-01/vaults/model_vaultproperties.go new file mode 100644 index 00000000000..a5e381c4dd9 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_vaultproperties.go @@ -0,0 +1,24 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultProperties struct { + AccessPolicies *[]AccessPolicyEntry `json:"accessPolicies,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + EnablePurgeProtection *bool `json:"enablePurgeProtection,omitempty"` + EnableRbacAuthorization *bool `json:"enableRbacAuthorization,omitempty"` + EnableSoftDelete *bool `json:"enableSoftDelete,omitempty"` + EnabledForDeployment *bool `json:"enabledForDeployment,omitempty"` + EnabledForDiskEncryption *bool `json:"enabledForDiskEncryption,omitempty"` + EnabledForTemplateDeployment *bool `json:"enabledForTemplateDeployment,omitempty"` + HsmPoolResourceId *string `json:"hsmPoolResourceId,omitempty"` + NetworkAcls *NetworkRuleSet `json:"networkAcls,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnectionItem `json:"privateEndpointConnections,omitempty"` + ProvisioningState *VaultProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` + Sku Sku `json:"sku"` + SoftDeleteRetentionInDays *int64 `json:"softDeleteRetentionInDays,omitempty"` + TenantId string `json:"tenantId"` + VaultUri *string `json:"vaultUri,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/model_virtualnetworkrule.go b/resource-manager/keyvault/2024-11-01/vaults/model_virtualnetworkrule.go new file mode 100644 index 00000000000..cd5b11b8aa7 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/model_virtualnetworkrule.go @@ -0,0 +1,9 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkRule struct { + Id string `json:"id"` + IgnoreMissingVnetServiceEndpoint *bool `json:"ignoreMissingVnetServiceEndpoint,omitempty"` +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/predicates.go b/resource-manager/keyvault/2024-11-01/vaults/predicates.go new file mode 100644 index 00000000000..ded74b94926 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/predicates.go @@ -0,0 +1,83 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedVaultOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeletedVaultOperationPredicate) Matches(input DeletedVault) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type VaultOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p VaultOperationPredicate) Matches(input Vault) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/keyvault/2024-11-01/vaults/version.go b/resource-manager/keyvault/2024-11-01/vaults/version.go new file mode 100644 index 00000000000..c7e3db7c550 --- /dev/null +++ b/resource-manager/keyvault/2024-11-01/vaults/version.go @@ -0,0 +1,10 @@ +package vaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/vaults/2024-11-01" +} diff --git a/resource-manager/managedidentity/2024-11-30/client.go b/resource-manager/managedidentity/2024-11-30/client.go new file mode 100644 index 00000000000..a971299379b --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/client.go @@ -0,0 +1,28 @@ +package v2024_11_30 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/managedidentity/2024-11-30/managedidentities" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + ManagedIdentities *managedidentities.ManagedIdentitiesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + managedIdentitiesClient, err := managedidentities.NewManagedIdentitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedIdentities client: %+v", err) + } + configureFunc(managedIdentitiesClient.Client) + + return &Client{ + ManagedIdentities: managedIdentitiesClient, + }, nil +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/README.md b/resource-manager/managedidentity/2024-11-30/managedidentities/README.md new file mode 100644 index 00000000000..775f465cf87 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/README.md @@ -0,0 +1,215 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/managedidentity/2024-11-30/managedidentities` Documentation + +The `managedidentities` SDK allows for interaction with Azure Resource Manager `managedidentity` (API Version `2024-11-30`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/managedidentity/2024-11-30/managedidentities" +``` + + +### Client Initialization + +```go +client := managedidentities.NewManagedIdentitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedIdentitiesClient.FederatedIdentityCredentialsCreateOrUpdate` + +```go +ctx := context.TODO() +id := managedidentities.NewFederatedIdentityCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName", "federatedIdentityCredentialName") + +payload := managedidentities.FederatedIdentityCredential{ + // ... +} + + +read, err := client.FederatedIdentityCredentialsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.FederatedIdentityCredentialsDelete` + +```go +ctx := context.TODO() +id := managedidentities.NewFederatedIdentityCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName", "federatedIdentityCredentialName") + +read, err := client.FederatedIdentityCredentialsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.FederatedIdentityCredentialsGet` + +```go +ctx := context.TODO() +id := managedidentities.NewFederatedIdentityCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName", "federatedIdentityCredentialName") + +read, err := client.FederatedIdentityCredentialsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.FederatedIdentityCredentialsList` + +```go +ctx := context.TODO() +id := commonids.NewUserAssignedIdentityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName") + +// alternatively `client.FederatedIdentityCredentialsList(ctx, id, managedidentities.DefaultFederatedIdentityCredentialsListOperationOptions())` can be used to do batched pagination +items, err := client.FederatedIdentityCredentialsListComplete(ctx, id, managedidentities.DefaultFederatedIdentityCredentialsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedIdentitiesClient.SystemAssignedIdentitiesGetByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.SystemAssignedIdentitiesGetByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewUserAssignedIdentityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName") + +payload := managedidentities.Identity{ + // ... +} + + +read, err := client.UserAssignedIdentitiesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesDelete` + +```go +ctx := context.TODO() +id := commonids.NewUserAssignedIdentityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName") + +read, err := client.UserAssignedIdentitiesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesGet` + +```go +ctx := context.TODO() +id := commonids.NewUserAssignedIdentityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName") + +read, err := client.UserAssignedIdentitiesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.UserAssignedIdentitiesListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.UserAssignedIdentitiesListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.UserAssignedIdentitiesListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.UserAssignedIdentitiesListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedIdentitiesClient.UserAssignedIdentitiesUpdate` + +```go +ctx := context.TODO() +id := commonids.NewUserAssignedIdentityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName") + +payload := managedidentities.IdentityUpdate{ + // ... +} + + +read, err := client.UserAssignedIdentitiesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/client.go b/resource-manager/managedidentity/2024-11-30/managedidentities/client.go new file mode 100644 index 00000000000..d3f9d4da8d6 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/client.go @@ -0,0 +1,26 @@ +package managedidentities + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitiesClient struct { + Client *resourcemanager.Client +} + +func NewManagedIdentitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedIdentitiesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedidentities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedIdentitiesClient: %+v", err) + } + + return &ManagedIdentitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/constants.go b/resource-manager/managedidentity/2024-11-30/managedidentities/constants.go new file mode 100644 index 00000000000..b5bc6f9a115 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/constants.go @@ -0,0 +1,51 @@ +package managedidentities + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IsolationScope string + +const ( + IsolationScopeNone IsolationScope = "None" + IsolationScopeRegional IsolationScope = "Regional" +) + +func PossibleValuesForIsolationScope() []string { + return []string{ + string(IsolationScopeNone), + string(IsolationScopeRegional), + } +} + +func (s *IsolationScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsolationScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsolationScope(input string) (*IsolationScope, error) { + vals := map[string]IsolationScope{ + "none": IsolationScopeNone, + "regional": IsolationScopeRegional, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsolationScope(input) + return &out, nil +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential.go b/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential.go new file mode 100644 index 00000000000..489ac28fed7 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential.go @@ -0,0 +1,139 @@ +package managedidentities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FederatedIdentityCredentialId{}) +} + +var _ resourceids.ResourceId = &FederatedIdentityCredentialId{} + +// FederatedIdentityCredentialId is a struct representing the Resource ID for a Federated Identity Credential +type FederatedIdentityCredentialId struct { + SubscriptionId string + ResourceGroupName string + UserAssignedIdentityName string + FederatedIdentityCredentialName string +} + +// NewFederatedIdentityCredentialID returns a new FederatedIdentityCredentialId struct +func NewFederatedIdentityCredentialID(subscriptionId string, resourceGroupName string, userAssignedIdentityName string, federatedIdentityCredentialName string) FederatedIdentityCredentialId { + return FederatedIdentityCredentialId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + UserAssignedIdentityName: userAssignedIdentityName, + FederatedIdentityCredentialName: federatedIdentityCredentialName, + } +} + +// ParseFederatedIdentityCredentialID parses 'input' into a FederatedIdentityCredentialId +func ParseFederatedIdentityCredentialID(input string) (*FederatedIdentityCredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(&FederatedIdentityCredentialId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FederatedIdentityCredentialId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFederatedIdentityCredentialIDInsensitively parses 'input' case-insensitively into a FederatedIdentityCredentialId +// note: this method should only be used for API response data and not user input +func ParseFederatedIdentityCredentialIDInsensitively(input string) (*FederatedIdentityCredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(&FederatedIdentityCredentialId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FederatedIdentityCredentialId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FederatedIdentityCredentialId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.UserAssignedIdentityName, ok = input.Parsed["userAssignedIdentityName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userAssignedIdentityName", input) + } + + if id.FederatedIdentityCredentialName, ok = input.Parsed["federatedIdentityCredentialName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "federatedIdentityCredentialName", input) + } + + return nil +} + +// ValidateFederatedIdentityCredentialID checks that 'input' can be parsed as a Federated Identity Credential ID +func ValidateFederatedIdentityCredentialID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseFederatedIdentityCredentialID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Federated Identity Credential ID +func (id FederatedIdentityCredentialId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities/%s/federatedIdentityCredentials/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.UserAssignedIdentityName, id.FederatedIdentityCredentialName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Federated Identity Credential ID +func (id FederatedIdentityCredentialId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagedIdentity", "Microsoft.ManagedIdentity", "Microsoft.ManagedIdentity"), + resourceids.StaticSegment("staticUserAssignedIdentities", "userAssignedIdentities", "userAssignedIdentities"), + resourceids.UserSpecifiedSegment("userAssignedIdentityName", "userAssignedIdentityName"), + resourceids.StaticSegment("staticFederatedIdentityCredentials", "federatedIdentityCredentials", "federatedIdentityCredentials"), + resourceids.UserSpecifiedSegment("federatedIdentityCredentialName", "federatedIdentityCredentialName"), + } +} + +// String returns a human-readable description of this Federated Identity Credential ID +func (id FederatedIdentityCredentialId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("User Assigned Identity Name: %q", id.UserAssignedIdentityName), + fmt.Sprintf("Federated Identity Credential Name: %q", id.FederatedIdentityCredentialName), + } + return fmt.Sprintf("Federated Identity Credential (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential_test.go b/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential_test.go new file mode 100644 index 00000000000..c7f261afc83 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/id_federatedidentitycredential_test.go @@ -0,0 +1,327 @@ +package managedidentities + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &FederatedIdentityCredentialId{} + +func TestNewFederatedIdentityCredentialID(t *testing.T) { + id := NewFederatedIdentityCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName", "federatedIdentityCredentialName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.UserAssignedIdentityName != "userAssignedIdentityName" { + t.Fatalf("Expected %q but got %q for Segment 'UserAssignedIdentityName'", id.UserAssignedIdentityName, "userAssignedIdentityName") + } + + if id.FederatedIdentityCredentialName != "federatedIdentityCredentialName" { + t.Fatalf("Expected %q but got %q for Segment 'FederatedIdentityCredentialName'", id.FederatedIdentityCredentialName, "federatedIdentityCredentialName") + } +} + +func TestFormatFederatedIdentityCredentialID(t *testing.T) { + actual := NewFederatedIdentityCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "userAssignedIdentityName", "federatedIdentityCredentialName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials/federatedIdentityCredentialName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFederatedIdentityCredentialID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FederatedIdentityCredentialId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials/federatedIdentityCredentialName", + Expected: &FederatedIdentityCredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + UserAssignedIdentityName: "userAssignedIdentityName", + FederatedIdentityCredentialName: "federatedIdentityCredentialName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials/federatedIdentityCredentialName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFederatedIdentityCredentialID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.UserAssignedIdentityName != v.Expected.UserAssignedIdentityName { + t.Fatalf("Expected %q but got %q for UserAssignedIdentityName", v.Expected.UserAssignedIdentityName, actual.UserAssignedIdentityName) + } + + if actual.FederatedIdentityCredentialName != v.Expected.FederatedIdentityCredentialName { + t.Fatalf("Expected %q but got %q for FederatedIdentityCredentialName", v.Expected.FederatedIdentityCredentialName, actual.FederatedIdentityCredentialName) + } + + } +} + +func TestParseFederatedIdentityCredentialIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FederatedIdentityCredentialId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy/uSeRaSsIgNeDiDeNtItIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy/uSeRaSsIgNeDiDeNtItIeS/uSeRaSsIgNeDiDeNtItYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy/uSeRaSsIgNeDiDeNtItIeS/uSeRaSsIgNeDiDeNtItYnAmE/fEdErAtEdIdEnTiTyCrEdEnTiAlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials/federatedIdentityCredentialName", + Expected: &FederatedIdentityCredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + UserAssignedIdentityName: "userAssignedIdentityName", + FederatedIdentityCredentialName: "federatedIdentityCredentialName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/userAssignedIdentityName/federatedIdentityCredentials/federatedIdentityCredentialName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy/uSeRaSsIgNeDiDeNtItIeS/uSeRaSsIgNeDiDeNtItYnAmE/fEdErAtEdIdEnTiTyCrEdEnTiAlS/fEdErAtEdIdEnTiTyCrEdEnTiAlNaMe", + Expected: &FederatedIdentityCredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + UserAssignedIdentityName: "uSeRaSsIgNeDiDeNtItYnAmE", + FederatedIdentityCredentialName: "fEdErAtEdIdEnTiTyCrEdEnTiAlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mAnAgEdIdEnTiTy/uSeRaSsIgNeDiDeNtItIeS/uSeRaSsIgNeDiDeNtItYnAmE/fEdErAtEdIdEnTiTyCrEdEnTiAlS/fEdErAtEdIdEnTiTyCrEdEnTiAlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFederatedIdentityCredentialIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.UserAssignedIdentityName != v.Expected.UserAssignedIdentityName { + t.Fatalf("Expected %q but got %q for UserAssignedIdentityName", v.Expected.UserAssignedIdentityName, actual.UserAssignedIdentityName) + } + + if actual.FederatedIdentityCredentialName != v.Expected.FederatedIdentityCredentialName { + t.Fatalf("Expected %q but got %q for FederatedIdentityCredentialName", v.Expected.FederatedIdentityCredentialName, actual.FederatedIdentityCredentialName) + } + + } +} + +func TestSegmentsForFederatedIdentityCredentialId(t *testing.T) { + segments := FederatedIdentityCredentialId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FederatedIdentityCredentialId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialscreateorupdate.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialscreateorupdate.go new file mode 100644 index 00000000000..7775539a8b2 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialscreateorupdate.go @@ -0,0 +1,58 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FederatedIdentityCredential +} + +// FederatedIdentityCredentialsCreateOrUpdate ... +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsCreateOrUpdate(ctx context.Context, id FederatedIdentityCredentialId, input FederatedIdentityCredential) (result FederatedIdentityCredentialsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model FederatedIdentityCredential + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsdelete.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsdelete.go new file mode 100644 index 00000000000..7920dca4fed --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsdelete.go @@ -0,0 +1,47 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// FederatedIdentityCredentialsDelete ... +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsDelete(ctx context.Context, id FederatedIdentityCredentialId) (result FederatedIdentityCredentialsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsget.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsget.go new file mode 100644 index 00000000000..0fb8d1bdde0 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialsget.go @@ -0,0 +1,53 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FederatedIdentityCredential +} + +// FederatedIdentityCredentialsGet ... +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsGet(ctx context.Context, id FederatedIdentityCredentialId) (result FederatedIdentityCredentialsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model FederatedIdentityCredential + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialslist.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialslist.go new file mode 100644 index 00000000000..a4b54b9a88f --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_federatedidentitycredentialslist.go @@ -0,0 +1,135 @@ +package managedidentities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]FederatedIdentityCredential +} + +type FederatedIdentityCredentialsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []FederatedIdentityCredential +} + +type FederatedIdentityCredentialsListOperationOptions struct { + Top *int64 +} + +func DefaultFederatedIdentityCredentialsListOperationOptions() FederatedIdentityCredentialsListOperationOptions { + return FederatedIdentityCredentialsListOperationOptions{} +} + +func (o FederatedIdentityCredentialsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o FederatedIdentityCredentialsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o FederatedIdentityCredentialsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type FederatedIdentityCredentialsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *FederatedIdentityCredentialsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// FederatedIdentityCredentialsList ... +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsList(ctx context.Context, id commonids.UserAssignedIdentityId, options FederatedIdentityCredentialsListOperationOptions) (result FederatedIdentityCredentialsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &FederatedIdentityCredentialsListCustomPager{}, + Path: fmt.Sprintf("%s/federatedIdentityCredentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]FederatedIdentityCredential `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// FederatedIdentityCredentialsListComplete retrieves all the results into a single object +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsListComplete(ctx context.Context, id commonids.UserAssignedIdentityId, options FederatedIdentityCredentialsListOperationOptions) (FederatedIdentityCredentialsListCompleteResult, error) { + return c.FederatedIdentityCredentialsListCompleteMatchingPredicate(ctx, id, options, FederatedIdentityCredentialOperationPredicate{}) +} + +// FederatedIdentityCredentialsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedIdentitiesClient) FederatedIdentityCredentialsListCompleteMatchingPredicate(ctx context.Context, id commonids.UserAssignedIdentityId, options FederatedIdentityCredentialsListOperationOptions, predicate FederatedIdentityCredentialOperationPredicate) (result FederatedIdentityCredentialsListCompleteResult, err error) { + items := make([]FederatedIdentityCredential, 0) + + resp, err := c.FederatedIdentityCredentialsList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = FederatedIdentityCredentialsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_systemassignedidentitiesgetbyscope.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_systemassignedidentitiesgetbyscope.go new file mode 100644 index 00000000000..d9a7eb188f5 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_systemassignedidentitiesgetbyscope.go @@ -0,0 +1,55 @@ +package managedidentities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemAssignedIdentitiesGetByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SystemAssignedIdentity +} + +// SystemAssignedIdentitiesGetByScope ... +func (c ManagedIdentitiesClient) SystemAssignedIdentitiesGetByScope(ctx context.Context, id commonids.ScopeId) (result SystemAssignedIdentitiesGetByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.ManagedIdentity/identities/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SystemAssignedIdentity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiescreateorupdate.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiescreateorupdate.go new file mode 100644 index 00000000000..7aba6559932 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiescreateorupdate.go @@ -0,0 +1,59 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Identity +} + +// UserAssignedIdentitiesCreateOrUpdate ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesCreateOrUpdate(ctx context.Context, id commonids.UserAssignedIdentityId, input Identity) (result UserAssignedIdentitiesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Identity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesdelete.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesdelete.go new file mode 100644 index 00000000000..df88b3eddcb --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesdelete.go @@ -0,0 +1,48 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// UserAssignedIdentitiesDelete ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesDelete(ctx context.Context, id commonids.UserAssignedIdentityId) (result UserAssignedIdentitiesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesget.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesget.go new file mode 100644 index 00000000000..d2eba6eaaea --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesget.go @@ -0,0 +1,54 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Identity +} + +// UserAssignedIdentitiesGet ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesGet(ctx context.Context, id commonids.UserAssignedIdentityId) (result UserAssignedIdentitiesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Identity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbyresourcegroup.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbyresourcegroup.go new file mode 100644 index 00000000000..9027b4bb35a --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbyresourcegroup.go @@ -0,0 +1,106 @@ +package managedidentities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Identity +} + +type UserAssignedIdentitiesListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Identity +} + +type UserAssignedIdentitiesListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *UserAssignedIdentitiesListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// UserAssignedIdentitiesListByResourceGroup ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result UserAssignedIdentitiesListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &UserAssignedIdentitiesListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Identity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UserAssignedIdentitiesListByResourceGroupComplete retrieves all the results into a single object +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (UserAssignedIdentitiesListByResourceGroupCompleteResult, error) { + return c.UserAssignedIdentitiesListByResourceGroupCompleteMatchingPredicate(ctx, id, IdentityOperationPredicate{}) +} + +// UserAssignedIdentitiesListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate IdentityOperationPredicate) (result UserAssignedIdentitiesListByResourceGroupCompleteResult, err error) { + items := make([]Identity, 0) + + resp, err := c.UserAssignedIdentitiesListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = UserAssignedIdentitiesListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbysubscription.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbysubscription.go new file mode 100644 index 00000000000..320f5b615a6 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitieslistbysubscription.go @@ -0,0 +1,106 @@ +package managedidentities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Identity +} + +type UserAssignedIdentitiesListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Identity +} + +type UserAssignedIdentitiesListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *UserAssignedIdentitiesListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// UserAssignedIdentitiesListBySubscription ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result UserAssignedIdentitiesListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &UserAssignedIdentitiesListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Identity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UserAssignedIdentitiesListBySubscriptionComplete retrieves all the results into a single object +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (UserAssignedIdentitiesListBySubscriptionCompleteResult, error) { + return c.UserAssignedIdentitiesListBySubscriptionCompleteMatchingPredicate(ctx, id, IdentityOperationPredicate{}) +} + +// UserAssignedIdentitiesListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedIdentitiesClient) UserAssignedIdentitiesListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate IdentityOperationPredicate) (result UserAssignedIdentitiesListBySubscriptionCompleteResult, err error) { + items := make([]Identity, 0) + + resp, err := c.UserAssignedIdentitiesListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = UserAssignedIdentitiesListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesupdate.go b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesupdate.go new file mode 100644 index 00000000000..ab9aa1b8a67 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/method_userassignedidentitiesupdate.go @@ -0,0 +1,58 @@ +package managedidentities + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentitiesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Identity +} + +// UserAssignedIdentitiesUpdate ... +func (c ManagedIdentitiesClient) UserAssignedIdentitiesUpdate(ctx context.Context, id commonids.UserAssignedIdentityId, input IdentityUpdate) (result UserAssignedIdentitiesUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Identity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredential.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredential.go new file mode 100644 index 00000000000..16056aaf445 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredential.go @@ -0,0 +1,16 @@ +package managedidentities + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredential struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *FederatedIdentityCredentialProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredentialproperties.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredentialproperties.go new file mode 100644 index 00000000000..91cda7e7315 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_federatedidentitycredentialproperties.go @@ -0,0 +1,10 @@ +package managedidentities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialProperties struct { + Audiences []string `json:"audiences"` + Issuer string `json:"issuer"` + Subject string `json:"subject"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_identity.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_identity.go new file mode 100644 index 00000000000..3bf1f9fa08a --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_identity.go @@ -0,0 +1,18 @@ +package managedidentities + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Identity struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *UserAssignedIdentityProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_identityupdate.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_identityupdate.go new file mode 100644 index 00000000000..d217eb7c202 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_identityupdate.go @@ -0,0 +1,18 @@ +package managedidentities + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityUpdate struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UserAssignedIdentityProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentity.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentity.go new file mode 100644 index 00000000000..228e6b4a213 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentity.go @@ -0,0 +1,18 @@ +package managedidentities + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemAssignedIdentity struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SystemAssignedIdentityProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentityproperties.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentityproperties.go new file mode 100644 index 00000000000..b4dc874c1e4 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_systemassignedidentityproperties.go @@ -0,0 +1,11 @@ +package managedidentities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemAssignedIdentityProperties struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecretURL *string `json:"clientSecretUrl,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/model_userassignedidentityproperties.go b/resource-manager/managedidentity/2024-11-30/managedidentities/model_userassignedidentityproperties.go new file mode 100644 index 00000000000..30fe32dc64e --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/model_userassignedidentityproperties.go @@ -0,0 +1,11 @@ +package managedidentities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentityProperties struct { + ClientId *string `json:"clientId,omitempty"` + IsolationScope *IsolationScope `json:"isolationScope,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/predicates.go b/resource-manager/managedidentity/2024-11-30/managedidentities/predicates.go new file mode 100644 index 00000000000..d881e5b06f3 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/predicates.go @@ -0,0 +1,55 @@ +package managedidentities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FederatedIdentityCredentialOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p FederatedIdentityCredentialOperationPredicate) Matches(input FederatedIdentityCredential) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type IdentityOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p IdentityOperationPredicate) Matches(input Identity) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/managedidentity/2024-11-30/managedidentities/version.go b/resource-manager/managedidentity/2024-11-30/managedidentities/version.go new file mode 100644 index 00000000000..5b8559f3410 --- /dev/null +++ b/resource-manager/managedidentity/2024-11-30/managedidentities/version.go @@ -0,0 +1,10 @@ +package managedidentities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-30" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedidentities/2024-11-30" +} diff --git a/resource-manager/quota/2025-03-01/client.go b/resource-manager/quota/2025-03-01/client.go new file mode 100644 index 00000000000..d60eb395d8a --- /dev/null +++ b/resource-manager/quota/2025-03-01/client.go @@ -0,0 +1,109 @@ +package v2025_03_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimitrequest" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimits" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotas" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotassubscriptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotainformation" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotarequests" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocation" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest" + "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/usagesinformation" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + GroupQuotaLimitRequest *groupquotalimitrequest.GroupQuotaLimitRequestClient + GroupQuotaLimits *groupquotalimits.GroupQuotaLimitsClient + GroupQuotaSubscriptionRequests *groupquotasubscriptionrequests.GroupQuotaSubscriptionRequestsClient + GroupQuotas *groupquotas.GroupQuotasClient + GroupQuotasSubscriptions *groupquotassubscriptions.GroupQuotasSubscriptionsClient + QuotaInformation *quotainformation.QuotaInformationClient + QuotaRequests *quotarequests.QuotaRequestsClient + SubscriptionQuotaAllocation *subscriptionquotaallocation.SubscriptionQuotaAllocationClient + SubscriptionQuotaAllocationRequest *subscriptionquotaallocationrequest.SubscriptionQuotaAllocationRequestClient + UsagesInformation *usagesinformation.UsagesInformationClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + groupQuotaLimitRequestClient, err := groupquotalimitrequest.NewGroupQuotaLimitRequestClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupQuotaLimitRequest client: %+v", err) + } + configureFunc(groupQuotaLimitRequestClient.Client) + + groupQuotaLimitsClient, err := groupquotalimits.NewGroupQuotaLimitsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupQuotaLimits client: %+v", err) + } + configureFunc(groupQuotaLimitsClient.Client) + + groupQuotaSubscriptionRequestsClient, err := groupquotasubscriptionrequests.NewGroupQuotaSubscriptionRequestsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupQuotaSubscriptionRequests client: %+v", err) + } + configureFunc(groupQuotaSubscriptionRequestsClient.Client) + + groupQuotasClient, err := groupquotas.NewGroupQuotasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupQuotas client: %+v", err) + } + configureFunc(groupQuotasClient.Client) + + groupQuotasSubscriptionsClient, err := groupquotassubscriptions.NewGroupQuotasSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupQuotasSubscriptions client: %+v", err) + } + configureFunc(groupQuotasSubscriptionsClient.Client) + + quotaInformationClient, err := quotainformation.NewQuotaInformationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QuotaInformation client: %+v", err) + } + configureFunc(quotaInformationClient.Client) + + quotaRequestsClient, err := quotarequests.NewQuotaRequestsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QuotaRequests client: %+v", err) + } + configureFunc(quotaRequestsClient.Client) + + subscriptionQuotaAllocationClient, err := subscriptionquotaallocation.NewSubscriptionQuotaAllocationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SubscriptionQuotaAllocation client: %+v", err) + } + configureFunc(subscriptionQuotaAllocationClient.Client) + + subscriptionQuotaAllocationRequestClient, err := subscriptionquotaallocationrequest.NewSubscriptionQuotaAllocationRequestClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SubscriptionQuotaAllocationRequest client: %+v", err) + } + configureFunc(subscriptionQuotaAllocationRequestClient.Client) + + usagesInformationClient, err := usagesinformation.NewUsagesInformationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UsagesInformation client: %+v", err) + } + configureFunc(usagesInformationClient.Client) + + return &Client{ + GroupQuotaLimitRequest: groupQuotaLimitRequestClient, + GroupQuotaLimits: groupQuotaLimitsClient, + GroupQuotaSubscriptionRequests: groupQuotaSubscriptionRequestsClient, + GroupQuotas: groupQuotasClient, + GroupQuotasSubscriptions: groupQuotasSubscriptionsClient, + QuotaInformation: quotaInformationClient, + QuotaRequests: quotaRequestsClient, + SubscriptionQuotaAllocation: subscriptionQuotaAllocationClient, + SubscriptionQuotaAllocationRequest: subscriptionQuotaAllocationRequestClient, + UsagesInformation: usagesInformationClient, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/README.md b/resource-manager/quota/2025-03-01/groupquotalimitrequest/README.md new file mode 100644 index 00000000000..e9d67de2268 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimitrequest` Documentation + +The `groupquotalimitrequest` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimitrequest" +``` + + +### Client Initialization + +```go +client := groupquotalimitrequest.NewGroupQuotaLimitRequestClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupQuotaLimitRequestClient.GroupQuotaLimitsRequestGet` + +```go +ctx := context.TODO() +id := groupquotalimitrequest.NewGroupQuotaRequestID("managementGroupId", "groupQuotaName", "requestId") + +read, err := client.GroupQuotaLimitsRequestGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupQuotaLimitRequestClient.GroupQuotaLimitsRequestList` + +```go +ctx := context.TODO() +id := groupquotalimitrequest.NewResourceProviderID("managementGroupId", "groupQuotaName", "resourceProviderName") + +// alternatively `client.GroupQuotaLimitsRequestList(ctx, id, groupquotalimitrequest.DefaultGroupQuotaLimitsRequestListOperationOptions())` can be used to do batched pagination +items, err := client.GroupQuotaLimitsRequestListComplete(ctx, id, groupquotalimitrequest.DefaultGroupQuotaLimitsRequestListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/client.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/client.go new file mode 100644 index 00000000000..a0d33852711 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/client.go @@ -0,0 +1,26 @@ +package groupquotalimitrequest + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitRequestClient struct { + Client *resourcemanager.Client +} + +func NewGroupQuotaLimitRequestClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupQuotaLimitRequestClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "groupquotalimitrequest", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupQuotaLimitRequestClient: %+v", err) + } + + return &GroupQuotaLimitRequestClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/constants.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/constants.go new file mode 100644 index 00000000000..914ab499c96 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/constants.go @@ -0,0 +1,66 @@ +package groupquotalimitrequest + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest.go new file mode 100644 index 00000000000..981111a13b2 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest.go @@ -0,0 +1,132 @@ +package groupquotalimitrequest + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaRequestId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaRequestId{} + +// GroupQuotaRequestId is a struct representing the Resource ID for a Group Quota Request +type GroupQuotaRequestId struct { + ManagementGroupId string + GroupQuotaName string + RequestId string +} + +// NewGroupQuotaRequestID returns a new GroupQuotaRequestId struct +func NewGroupQuotaRequestID(managementGroupId string, groupQuotaName string, requestId string) GroupQuotaRequestId { + return GroupQuotaRequestId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + RequestId: requestId, + } +} + +// ParseGroupQuotaRequestID parses 'input' into a GroupQuotaRequestId +func ParseGroupQuotaRequestID(input string) (*GroupQuotaRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaRequestIDInsensitively parses 'input' case-insensitively into a GroupQuotaRequestId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaRequestIDInsensitively(input string) (*GroupQuotaRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.RequestId, ok = input.Parsed["requestId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "requestId", input) + } + + return nil +} + +// ValidateGroupQuotaRequestID checks that 'input' can be parsed as a Group Quota Request ID +func ValidateGroupQuotaRequestID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota Request ID +func (id GroupQuotaRequestId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s/groupQuotaRequests/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName, id.RequestId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota Request ID +func (id GroupQuotaRequestId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticGroupQuotaRequests", "groupQuotaRequests", "groupQuotaRequests"), + resourceids.UserSpecifiedSegment("requestId", "requestId"), + } +} + +// String returns a human-readable description of this Group Quota Request ID +func (id GroupQuotaRequestId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Request: %q", id.RequestId), + } + return fmt.Sprintf("Group Quota Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest_test.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest_test.go new file mode 100644 index 00000000000..91e399a341b --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_groupquotarequest_test.go @@ -0,0 +1,312 @@ +package groupquotalimitrequest + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaRequestId{} + +func TestNewGroupQuotaRequestID(t *testing.T) { + id := NewGroupQuotaRequestID("managementGroupId", "groupQuotaName", "requestId") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.RequestId != "requestId" { + t.Fatalf("Expected %q but got %q for Segment 'RequestId'", id.RequestId, "requestId") + } +} + +func TestFormatGroupQuotaRequestID(t *testing.T) { + actual := NewGroupQuotaRequestID("managementGroupId", "groupQuotaName", "requestId").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests/requestId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests/requestId", + Expected: &GroupQuotaRequestId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + RequestId: "requestId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests/requestId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaRequestID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.RequestId != v.Expected.RequestId { + t.Fatalf("Expected %q but got %q for RequestId", v.Expected.RequestId, actual.RequestId) + } + + } +} + +func TestParseGroupQuotaRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/gRoUpQuOtArEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests/requestId", + Expected: &GroupQuotaRequestId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + RequestId: "requestId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/groupQuotaRequests/requestId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/gRoUpQuOtArEqUeStS/rEqUeStId", + Expected: &GroupQuotaRequestId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + RequestId: "rEqUeStId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/gRoUpQuOtArEqUeStS/rEqUeStId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaRequestIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.RequestId != v.Expected.RequestId { + t.Fatalf("Expected %q but got %q for RequestId", v.Expected.RequestId, actual.RequestId) + } + + } +} + +func TestSegmentsForGroupQuotaRequestId(t *testing.T) { + segments := GroupQuotaRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaRequestId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider.go new file mode 100644 index 00000000000..67b435b01ad --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider.go @@ -0,0 +1,132 @@ +package groupquotalimitrequest + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResourceProviderId{}) +} + +var _ resourceids.ResourceId = &ResourceProviderId{} + +// ResourceProviderId is a struct representing the Resource ID for a Resource Provider +type ResourceProviderId struct { + ManagementGroupId string + GroupQuotaName string + ResourceProviderName string +} + +// NewResourceProviderID returns a new ResourceProviderId struct +func NewResourceProviderID(managementGroupId string, groupQuotaName string, resourceProviderName string) ResourceProviderId { + return ResourceProviderId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + ResourceProviderName: resourceProviderName, + } +} + +// ParseResourceProviderID parses 'input' into a ResourceProviderId +func ParseResourceProviderID(input string) (*ResourceProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceProviderIDInsensitively parses 'input' case-insensitively into a ResourceProviderId +// note: this method should only be used for API response data and not user input +func ParseResourceProviderIDInsensitively(input string) (*ResourceProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceProviderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.ResourceProviderName, ok = input.Parsed["resourceProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceProviderName", input) + } + + return nil +} + +// ValidateResourceProviderID checks that 'input' can be parsed as a Resource Provider ID +func ValidateResourceProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseResourceProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Provider ID +func (id ResourceProviderId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s/resourceProviders/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName, id.ResourceProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Provider ID +func (id ResourceProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticResourceProviders", "resourceProviders", "resourceProviders"), + resourceids.UserSpecifiedSegment("resourceProviderName", "resourceProviderName"), + } +} + +// String returns a human-readable description of this Resource Provider ID +func (id ResourceProviderId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Resource Provider Name: %q", id.ResourceProviderName), + } + return fmt.Sprintf("Resource Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider_test.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider_test.go new file mode 100644 index 00000000000..b6120de7552 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/id_resourceprovider_test.go @@ -0,0 +1,312 @@ +package groupquotalimitrequest + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ResourceProviderId{} + +func TestNewResourceProviderID(t *testing.T) { + id := NewResourceProviderID("managementGroupId", "groupQuotaName", "resourceProviderName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.ResourceProviderName != "resourceProviderName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceProviderName'", id.ResourceProviderName, "resourceProviderName") + } +} + +func TestFormatResourceProviderID(t *testing.T) { + actual := NewResourceProviderID("managementGroupId", "groupQuotaName", "resourceProviderName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Expected: &ResourceProviderId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + } +} + +func TestParseResourceProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Expected: &ResourceProviderId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE", + Expected: &ResourceProviderId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + ResourceProviderName: "rEsOuRcEpRoViDeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + } +} + +func TestSegmentsForResourceProviderId(t *testing.T) { + segments := ResourceProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestget.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestget.go new file mode 100644 index 00000000000..ba4ed9b9d26 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestget.go @@ -0,0 +1,53 @@ +package groupquotalimitrequest + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitsRequestGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubmittedResourceRequestStatus +} + +// GroupQuotaLimitsRequestGet ... +func (c GroupQuotaLimitRequestClient) GroupQuotaLimitsRequestGet(ctx context.Context, id GroupQuotaRequestId) (result GroupQuotaLimitsRequestGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SubmittedResourceRequestStatus + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestlist.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestlist.go new file mode 100644 index 00000000000..0ac9203b619 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/method_groupquotalimitsrequestlist.go @@ -0,0 +1,134 @@ +package groupquotalimitrequest + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitsRequestListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SubmittedResourceRequestStatus +} + +type GroupQuotaLimitsRequestListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubmittedResourceRequestStatus +} + +type GroupQuotaLimitsRequestListOperationOptions struct { + Filter *string +} + +func DefaultGroupQuotaLimitsRequestListOperationOptions() GroupQuotaLimitsRequestListOperationOptions { + return GroupQuotaLimitsRequestListOperationOptions{} +} + +func (o GroupQuotaLimitsRequestListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GroupQuotaLimitsRequestListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GroupQuotaLimitsRequestListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type GroupQuotaLimitsRequestListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GroupQuotaLimitsRequestListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GroupQuotaLimitsRequestList ... +func (c GroupQuotaLimitRequestClient) GroupQuotaLimitsRequestList(ctx context.Context, id ResourceProviderId, options GroupQuotaLimitsRequestListOperationOptions) (result GroupQuotaLimitsRequestListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &GroupQuotaLimitsRequestListCustomPager{}, + Path: fmt.Sprintf("%s/groupQuotaRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SubmittedResourceRequestStatus `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GroupQuotaLimitsRequestListComplete retrieves all the results into a single object +func (c GroupQuotaLimitRequestClient) GroupQuotaLimitsRequestListComplete(ctx context.Context, id ResourceProviderId, options GroupQuotaLimitsRequestListOperationOptions) (GroupQuotaLimitsRequestListCompleteResult, error) { + return c.GroupQuotaLimitsRequestListCompleteMatchingPredicate(ctx, id, options, SubmittedResourceRequestStatusOperationPredicate{}) +} + +// GroupQuotaLimitsRequestListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupQuotaLimitRequestClient) GroupQuotaLimitsRequestListCompleteMatchingPredicate(ctx context.Context, id ResourceProviderId, options GroupQuotaLimitsRequestListOperationOptions, predicate SubmittedResourceRequestStatusOperationPredicate) (result GroupQuotaLimitsRequestListCompleteResult, err error) { + items := make([]SubmittedResourceRequestStatus, 0) + + resp, err := c.GroupQuotaLimitsRequestList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GroupQuotaLimitsRequestListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbase.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbase.go new file mode 100644 index 00000000000..eff7f62efb3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbase.go @@ -0,0 +1,8 @@ +package groupquotalimitrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaRequestBase struct { + Properties *GroupQuotaRequestBaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbaseproperties.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbaseproperties.go new file mode 100644 index 00000000000..029a5a26fa8 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbaseproperties.go @@ -0,0 +1,11 @@ +package groupquotalimitrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaRequestBaseProperties struct { + Comments *string `json:"comments,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *GroupQuotaRequestBasePropertiesName `json:"name,omitempty"` + Region *string `json:"region,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbasepropertiesname.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbasepropertiesname.go new file mode 100644 index 00000000000..a604ca61ee1 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_groupquotarequestbasepropertiesname.go @@ -0,0 +1,9 @@ +package groupquotalimitrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaRequestBasePropertiesName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatus.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatus.go new file mode 100644 index 00000000000..c47034abe10 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatus.go @@ -0,0 +1,16 @@ +package groupquotalimitrequest + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubmittedResourceRequestStatus struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubmittedResourceRequestStatusProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatusproperties.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatusproperties.go new file mode 100644 index 00000000000..0643bf11585 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/model_submittedresourcerequeststatusproperties.go @@ -0,0 +1,29 @@ +package groupquotalimitrequest + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubmittedResourceRequestStatusProperties struct { + FaultCode *string `json:"faultCode,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + RequestSubmitTime *string `json:"requestSubmitTime,omitempty"` + RequestedResource *GroupQuotaRequestBase `json:"requestedResource,omitempty"` +} + +func (o *SubmittedResourceRequestStatusProperties) GetRequestSubmitTimeAsTime() (*time.Time, error) { + if o.RequestSubmitTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RequestSubmitTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubmittedResourceRequestStatusProperties) SetRequestSubmitTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RequestSubmitTime = &formatted +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/predicates.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/predicates.go new file mode 100644 index 00000000000..8f2e2a15f13 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/predicates.go @@ -0,0 +1,27 @@ +package groupquotalimitrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubmittedResourceRequestStatusOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubmittedResourceRequestStatusOperationPredicate) Matches(input SubmittedResourceRequestStatus) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimitrequest/version.go b/resource-manager/quota/2025-03-01/groupquotalimitrequest/version.go new file mode 100644 index 00000000000..8889738b6e7 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimitrequest/version.go @@ -0,0 +1,10 @@ +package groupquotalimitrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/groupquotalimitrequest/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/README.md b/resource-manager/quota/2025-03-01/groupquotalimits/README.md new file mode 100644 index 00000000000..c7b293de117 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimits` Documentation + +The `groupquotalimits` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotalimits" +``` + + +### Client Initialization + +```go +client := groupquotalimits.NewGroupQuotaLimitsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupQuotaLimitsClient.List` + +```go +ctx := context.TODO() +id := groupquotalimits.NewGroupQuotaLimitID("managementGroupId", "groupQuotaName", "resourceProviderName", "groupQuotaLimitName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupQuotaLimitsClient.RequestUpdate` + +```go +ctx := context.TODO() +id := groupquotalimits.NewGroupQuotaLimitID("managementGroupId", "groupQuotaName", "resourceProviderName", "groupQuotaLimitName") + +payload := groupquotalimits.GroupQuotaLimitList{ + // ... +} + + +if err := client.RequestUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/client.go b/resource-manager/quota/2025-03-01/groupquotalimits/client.go new file mode 100644 index 00000000000..b36d63189b7 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/client.go @@ -0,0 +1,26 @@ +package groupquotalimits + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitsClient struct { + Client *resourcemanager.Client +} + +func NewGroupQuotaLimitsClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupQuotaLimitsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "groupquotalimits", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupQuotaLimitsClient: %+v", err) + } + + return &GroupQuotaLimitsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/constants.go b/resource-manager/quota/2025-03-01/groupquotalimits/constants.go new file mode 100644 index 00000000000..2a890114148 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/constants.go @@ -0,0 +1,66 @@ +package groupquotalimits + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit.go b/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit.go new file mode 100644 index 00000000000..de2630d48c8 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit.go @@ -0,0 +1,141 @@ +package groupquotalimits + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaLimitId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaLimitId{} + +// GroupQuotaLimitId is a struct representing the Resource ID for a Group Quota Limit +type GroupQuotaLimitId struct { + ManagementGroupId string + GroupQuotaName string + ResourceProviderName string + GroupQuotaLimitName string +} + +// NewGroupQuotaLimitID returns a new GroupQuotaLimitId struct +func NewGroupQuotaLimitID(managementGroupId string, groupQuotaName string, resourceProviderName string, groupQuotaLimitName string) GroupQuotaLimitId { + return GroupQuotaLimitId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + ResourceProviderName: resourceProviderName, + GroupQuotaLimitName: groupQuotaLimitName, + } +} + +// ParseGroupQuotaLimitID parses 'input' into a GroupQuotaLimitId +func ParseGroupQuotaLimitID(input string) (*GroupQuotaLimitId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaLimitId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaLimitId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaLimitIDInsensitively parses 'input' case-insensitively into a GroupQuotaLimitId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaLimitIDInsensitively(input string) (*GroupQuotaLimitId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaLimitId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaLimitId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaLimitId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.ResourceProviderName, ok = input.Parsed["resourceProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceProviderName", input) + } + + if id.GroupQuotaLimitName, ok = input.Parsed["groupQuotaLimitName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaLimitName", input) + } + + return nil +} + +// ValidateGroupQuotaLimitID checks that 'input' can be parsed as a Group Quota Limit ID +func ValidateGroupQuotaLimitID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaLimitID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota Limit ID +func (id GroupQuotaLimitId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s/resourceProviders/%s/groupQuotaLimits/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName, id.ResourceProviderName, id.GroupQuotaLimitName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota Limit ID +func (id GroupQuotaLimitId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticResourceProviders", "resourceProviders", "resourceProviders"), + resourceids.UserSpecifiedSegment("resourceProviderName", "resourceProviderName"), + resourceids.StaticSegment("staticGroupQuotaLimits", "groupQuotaLimits", "groupQuotaLimits"), + resourceids.UserSpecifiedSegment("groupQuotaLimitName", "groupQuotaLimitName"), + } +} + +// String returns a human-readable description of this Group Quota Limit ID +func (id GroupQuotaLimitId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Resource Provider Name: %q", id.ResourceProviderName), + fmt.Sprintf("Group Quota Limit Name: %q", id.GroupQuotaLimitName), + } + return fmt.Sprintf("Group Quota Limit (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit_test.go b/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit_test.go new file mode 100644 index 00000000000..9182e75234a --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/id_groupquotalimit_test.go @@ -0,0 +1,357 @@ +package groupquotalimits + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaLimitId{} + +func TestNewGroupQuotaLimitID(t *testing.T) { + id := NewGroupQuotaLimitID("managementGroupId", "groupQuotaName", "resourceProviderName", "groupQuotaLimitName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.ResourceProviderName != "resourceProviderName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceProviderName'", id.ResourceProviderName, "resourceProviderName") + } + + if id.GroupQuotaLimitName != "groupQuotaLimitName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaLimitName'", id.GroupQuotaLimitName, "groupQuotaLimitName") + } +} + +func TestFormatGroupQuotaLimitID(t *testing.T) { + actual := NewGroupQuotaLimitID("managementGroupId", "groupQuotaName", "resourceProviderName", "groupQuotaLimitName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits/groupQuotaLimitName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaLimitID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaLimitId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits/groupQuotaLimitName", + Expected: &GroupQuotaLimitId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + GroupQuotaLimitName: "groupQuotaLimitName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits/groupQuotaLimitName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaLimitID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.GroupQuotaLimitName != v.Expected.GroupQuotaLimitName { + t.Fatalf("Expected %q but got %q for GroupQuotaLimitName", v.Expected.GroupQuotaLimitName, actual.GroupQuotaLimitName) + } + + } +} + +func TestParseGroupQuotaLimitIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaLimitId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/gRoUpQuOtAlImItS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits/groupQuotaLimitName", + Expected: &GroupQuotaLimitId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + GroupQuotaLimitName: "groupQuotaLimitName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/groupQuotaLimits/groupQuotaLimitName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/gRoUpQuOtAlImItS/gRoUpQuOtAlImItNaMe", + Expected: &GroupQuotaLimitId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + ResourceProviderName: "rEsOuRcEpRoViDeRnAmE", + GroupQuotaLimitName: "gRoUpQuOtAlImItNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/gRoUpQuOtAlImItS/gRoUpQuOtAlImItNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaLimitIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.GroupQuotaLimitName != v.Expected.GroupQuotaLimitName { + t.Fatalf("Expected %q but got %q for GroupQuotaLimitName", v.Expected.GroupQuotaLimitName, actual.GroupQuotaLimitName) + } + + } +} + +func TestSegmentsForGroupQuotaLimitId(t *testing.T) { + segments := GroupQuotaLimitId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaLimitId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/method_list.go b/resource-manager/quota/2025-03-01/groupquotalimits/method_list.go new file mode 100644 index 00000000000..303efcd73cd --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/method_list.go @@ -0,0 +1,53 @@ +package groupquotalimits + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaLimitList +} + +// List ... +func (c GroupQuotaLimitsClient) List(ctx context.Context, id GroupQuotaLimitId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GroupQuotaLimitList + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/method_requestupdate.go b/resource-manager/quota/2025-03-01/groupquotalimits/method_requestupdate.go new file mode 100644 index 00000000000..bd237bd3062 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/method_requestupdate.go @@ -0,0 +1,75 @@ +package groupquotalimits + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaLimitList +} + +// RequestUpdate ... +func (c GroupQuotaLimitsClient) RequestUpdate(ctx context.Context, id GroupQuotaLimitId, input GroupQuotaLimitList) (result RequestUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RequestUpdateThenPoll performs RequestUpdate then polls until it's completed +func (c GroupQuotaLimitsClient) RequestUpdateThenPoll(ctx context.Context, id GroupQuotaLimitId, input GroupQuotaLimitList) error { + result, err := c.RequestUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RequestUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RequestUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedquotatosubscriptionlist.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedquotatosubscriptionlist.go new file mode 100644 index 00000000000..ce996e63f63 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedquotatosubscriptionlist.go @@ -0,0 +1,8 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllocatedQuotaToSubscriptionList struct { + Value *[]AllocatedToSubscription `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedtosubscription.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedtosubscription.go new file mode 100644 index 00000000000..1de0829ef0f --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_allocatedtosubscription.go @@ -0,0 +1,9 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllocatedToSubscription struct { + QuotaAllocated *int64 `json:"quotaAllocated,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetails.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetails.go new file mode 100644 index 00000000000..45280ead325 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetails.go @@ -0,0 +1,14 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaDetails struct { + AllocatedToSubscriptions *AllocatedQuotaToSubscriptionList `json:"allocatedToSubscriptions,omitempty"` + AvailableLimit *int64 `json:"availableLimit,omitempty"` + Comment *string `json:"comment,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *GroupQuotaDetailsName `json:"name,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetailsname.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetailsname.go new file mode 100644 index 00000000000..9de2e25a12c --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotadetailsname.go @@ -0,0 +1,9 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaDetailsName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimit.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimit.go new file mode 100644 index 00000000000..58a005aaa9f --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimit.go @@ -0,0 +1,8 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimit struct { + Properties *GroupQuotaDetails `json:"properties,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlist.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlist.go new file mode 100644 index 00000000000..d98d4204d7f --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlist.go @@ -0,0 +1,16 @@ +package groupquotalimits + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitList struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupQuotaLimitListProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlistproperties.go b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlistproperties.go new file mode 100644 index 00000000000..933c2d7ad47 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/model_groupquotalimitlistproperties.go @@ -0,0 +1,10 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaLimitListProperties struct { + NextLink *string `json:"nextLink,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + Value *[]GroupQuotaLimit `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotalimits/version.go b/resource-manager/quota/2025-03-01/groupquotalimits/version.go new file mode 100644 index 00000000000..bd38241547c --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotalimits/version.go @@ -0,0 +1,10 @@ +package groupquotalimits + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/groupquotalimits/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/README.md b/resource-manager/quota/2025-03-01/groupquotas/README.md new file mode 100644 index 00000000000..917d0a86a31 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotas` Documentation + +The `groupquotas` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotas" +``` + + +### Client Initialization + +```go +client := groupquotas.NewGroupQuotasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupQuotasClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := groupquotas.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +payload := groupquotas.GroupQuotasEntity{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GroupQuotasClient.Delete` + +```go +ctx := context.TODO() +id := groupquotas.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GroupQuotasClient.Get` + +```go +ctx := context.TODO() +id := groupquotas.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupQuotasClient.List` + +```go +ctx := context.TODO() +id := commonids.NewManagementGroupID("groupId") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GroupQuotasClient.Update` + +```go +ctx := context.TODO() +id := groupquotas.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +payload := groupquotas.GroupQuotasEntityPatch{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/quota/2025-03-01/groupquotas/client.go b/resource-manager/quota/2025-03-01/groupquotas/client.go new file mode 100644 index 00000000000..6c410d0cc8a --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/client.go @@ -0,0 +1,26 @@ +package groupquotas + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasClient struct { + Client *resourcemanager.Client +} + +func NewGroupQuotasClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupQuotasClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "groupquotas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupQuotasClient: %+v", err) + } + + return &GroupQuotasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/constants.go b/resource-manager/quota/2025-03-01/groupquotas/constants.go new file mode 100644 index 00000000000..4a5412ba3d8 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/constants.go @@ -0,0 +1,66 @@ +package groupquotas + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/id_groupquota.go b/resource-manager/quota/2025-03-01/groupquotas/id_groupquota.go new file mode 100644 index 00000000000..935f7f72027 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/id_groupquota.go @@ -0,0 +1,123 @@ +package groupquotas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaId{} + +// GroupQuotaId is a struct representing the Resource ID for a Group Quota +type GroupQuotaId struct { + ManagementGroupId string + GroupQuotaName string +} + +// NewGroupQuotaID returns a new GroupQuotaId struct +func NewGroupQuotaID(managementGroupId string, groupQuotaName string) GroupQuotaId { + return GroupQuotaId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + } +} + +// ParseGroupQuotaID parses 'input' into a GroupQuotaId +func ParseGroupQuotaID(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaIDInsensitively parses 'input' case-insensitively into a GroupQuotaId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaIDInsensitively(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + return nil +} + +// ValidateGroupQuotaID checks that 'input' can be parsed as a Group Quota ID +func ValidateGroupQuotaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota ID +func (id GroupQuotaId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota ID +func (id GroupQuotaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + } +} + +// String returns a human-readable description of this Group Quota ID +func (id GroupQuotaId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + } + return fmt.Sprintf("Group Quota (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/id_groupquota_test.go b/resource-manager/quota/2025-03-01/groupquotas/id_groupquota_test.go new file mode 100644 index 00000000000..872616d5d24 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/id_groupquota_test.go @@ -0,0 +1,267 @@ +package groupquotas + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaId{} + +func TestNewGroupQuotaID(t *testing.T) { + id := NewGroupQuotaID("managementGroupId", "groupQuotaName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } +} + +func TestFormatGroupQuotaID(t *testing.T) { + actual := NewGroupQuotaID("managementGroupId", "groupQuotaName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestParseGroupQuotaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Expected: &GroupQuotaId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestSegmentsForGroupQuotaId(t *testing.T) { + segments := GroupQuotaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/method_createorupdate.go b/resource-manager/quota/2025-03-01/groupquotas/method_createorupdate.go new file mode 100644 index 00000000000..695164d1469 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/method_createorupdate.go @@ -0,0 +1,75 @@ +package groupquotas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotasEntity +} + +// CreateOrUpdate ... +func (c GroupQuotasClient) CreateOrUpdate(ctx context.Context, id GroupQuotaId, input GroupQuotasEntity) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c GroupQuotasClient) CreateOrUpdateThenPoll(ctx context.Context, id GroupQuotaId, input GroupQuotasEntity) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/method_delete.go b/resource-manager/quota/2025-03-01/groupquotas/method_delete.go new file mode 100644 index 00000000000..7cc05e922f4 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/method_delete.go @@ -0,0 +1,70 @@ +package groupquotas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c GroupQuotasClient) Delete(ctx context.Context, id GroupQuotaId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c GroupQuotasClient) DeleteThenPoll(ctx context.Context, id GroupQuotaId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/method_get.go b/resource-manager/quota/2025-03-01/groupquotas/method_get.go new file mode 100644 index 00000000000..3e781a473c0 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/method_get.go @@ -0,0 +1,53 @@ +package groupquotas + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotasEntity +} + +// Get ... +func (c GroupQuotasClient) Get(ctx context.Context, id GroupQuotaId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GroupQuotasEntity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/method_list.go b/resource-manager/quota/2025-03-01/groupquotas/method_list.go new file mode 100644 index 00000000000..2a401dfbe16 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/method_list.go @@ -0,0 +1,106 @@ +package groupquotas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupQuotasEntity +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupQuotasEntity +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c GroupQuotasClient) List(ctx context.Context, id commonids.ManagementGroupId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Quota/groupQuotas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GroupQuotasEntity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c GroupQuotasClient) ListComplete(ctx context.Context, id commonids.ManagementGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, GroupQuotasEntityOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupQuotasClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ManagementGroupId, predicate GroupQuotasEntityOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GroupQuotasEntity, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/method_update.go b/resource-manager/quota/2025-03-01/groupquotas/method_update.go new file mode 100644 index 00000000000..ff5ec4bccad --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/method_update.go @@ -0,0 +1,75 @@ +package groupquotas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotasEntity +} + +// Update ... +func (c GroupQuotasClient) Update(ctx context.Context, id GroupQuotaId, input GroupQuotasEntityPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c GroupQuotasClient) UpdateThenPoll(ctx context.Context, id GroupQuotaId, input GroupQuotasEntityPatch) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentity.go b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentity.go new file mode 100644 index 00000000000..3a52d8182eb --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentity.go @@ -0,0 +1,16 @@ +package groupquotas + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasEntity struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupQuotasEntityBase `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybase.go b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybase.go new file mode 100644 index 00000000000..9fceaa4d95d --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybase.go @@ -0,0 +1,9 @@ +package groupquotas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasEntityBase struct { + DisplayName *string `json:"displayName,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybasepatch.go b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybasepatch.go new file mode 100644 index 00000000000..230e2694708 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitybasepatch.go @@ -0,0 +1,9 @@ +package groupquotas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasEntityBasePatch struct { + DisplayName *string `json:"displayName,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitypatch.go b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitypatch.go new file mode 100644 index 00000000000..c5543a2cb77 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/model_groupquotasentitypatch.go @@ -0,0 +1,16 @@ +package groupquotas + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasEntityPatch struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupQuotasEntityBasePatch `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/predicates.go b/resource-manager/quota/2025-03-01/groupquotas/predicates.go new file mode 100644 index 00000000000..8f6f6cfb113 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/predicates.go @@ -0,0 +1,27 @@ +package groupquotas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasEntityOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupQuotasEntityOperationPredicate) Matches(input GroupQuotasEntity) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/groupquotas/version.go b/resource-manager/quota/2025-03-01/groupquotas/version.go new file mode 100644 index 00000000000..1fb8a717ca0 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotas/version.go @@ -0,0 +1,10 @@ +package groupquotas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/groupquotas/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/README.md b/resource-manager/quota/2025-03-01/groupquotassubscriptions/README.md new file mode 100644 index 00000000000..4fd35b052f9 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotassubscriptions` Documentation + +The `groupquotassubscriptions` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotassubscriptions" +``` + + +### Client Initialization + +```go +client := groupquotassubscriptions.NewGroupQuotasSubscriptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupQuotasSubscriptionsClient.GroupQuotaSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := groupquotassubscriptions.NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012") + +if err := client.GroupQuotaSubscriptionsCreateOrUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GroupQuotasSubscriptionsClient.GroupQuotaSubscriptionsDelete` + +```go +ctx := context.TODO() +id := groupquotassubscriptions.NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012") + +if err := client.GroupQuotaSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GroupQuotasSubscriptionsClient.GroupQuotaSubscriptionsGet` + +```go +ctx := context.TODO() +id := groupquotassubscriptions.NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012") + +read, err := client.GroupQuotaSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupQuotasSubscriptionsClient.GroupQuotaSubscriptionsList` + +```go +ctx := context.TODO() +id := groupquotassubscriptions.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +// alternatively `client.GroupQuotaSubscriptionsList(ctx, id)` can be used to do batched pagination +items, err := client.GroupQuotaSubscriptionsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GroupQuotasSubscriptionsClient.GroupQuotaSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := groupquotassubscriptions.NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012") + +if err := client.GroupQuotaSubscriptionsUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/client.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/client.go new file mode 100644 index 00000000000..f116aca695d --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/client.go @@ -0,0 +1,26 @@ +package groupquotassubscriptions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotasSubscriptionsClient struct { + Client *resourcemanager.Client +} + +func NewGroupQuotasSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupQuotasSubscriptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "groupquotassubscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupQuotasSubscriptionsClient: %+v", err) + } + + return &GroupQuotasSubscriptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/constants.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/constants.go new file mode 100644 index 00000000000..e935b840684 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/constants.go @@ -0,0 +1,66 @@ +package groupquotassubscriptions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota.go new file mode 100644 index 00000000000..0d3563c6ba9 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota.go @@ -0,0 +1,123 @@ +package groupquotassubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaId{} + +// GroupQuotaId is a struct representing the Resource ID for a Group Quota +type GroupQuotaId struct { + ManagementGroupId string + GroupQuotaName string +} + +// NewGroupQuotaID returns a new GroupQuotaId struct +func NewGroupQuotaID(managementGroupId string, groupQuotaName string) GroupQuotaId { + return GroupQuotaId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + } +} + +// ParseGroupQuotaID parses 'input' into a GroupQuotaId +func ParseGroupQuotaID(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaIDInsensitively parses 'input' case-insensitively into a GroupQuotaId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaIDInsensitively(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + return nil +} + +// ValidateGroupQuotaID checks that 'input' can be parsed as a Group Quota ID +func ValidateGroupQuotaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota ID +func (id GroupQuotaId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota ID +func (id GroupQuotaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + } +} + +// String returns a human-readable description of this Group Quota ID +func (id GroupQuotaId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + } + return fmt.Sprintf("Group Quota (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota_test.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota_test.go new file mode 100644 index 00000000000..5a846e6b64b --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_groupquota_test.go @@ -0,0 +1,267 @@ +package groupquotassubscriptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaId{} + +func TestNewGroupQuotaID(t *testing.T) { + id := NewGroupQuotaID("managementGroupId", "groupQuotaName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } +} + +func TestFormatGroupQuotaID(t *testing.T) { + actual := NewGroupQuotaID("managementGroupId", "groupQuotaName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestParseGroupQuotaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Expected: &GroupQuotaId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestSegmentsForGroupQuotaId(t *testing.T) { + segments := GroupQuotaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription.go new file mode 100644 index 00000000000..e3c1a943bc3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription.go @@ -0,0 +1,132 @@ +package groupquotassubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SubscriptionId{}) +} + +var _ resourceids.ResourceId = &SubscriptionId{} + +// SubscriptionId is a struct representing the Resource ID for a Subscription +type SubscriptionId struct { + ManagementGroupId string + GroupQuotaName string + SubscriptionId string +} + +// NewSubscriptionID returns a new SubscriptionId struct +func NewSubscriptionID(managementGroupId string, groupQuotaName string, subscriptionId string) SubscriptionId { + return SubscriptionId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + SubscriptionId: subscriptionId, + } +} + +// ParseSubscriptionID parses 'input' into a SubscriptionId +func ParseSubscriptionID(input string) (*SubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSubscriptionIDInsensitively parses 'input' case-insensitively into a SubscriptionId +// note: this method should only be used for API response data and not user input +func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SubscriptionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + return nil +} + +// ValidateSubscriptionID checks that 'input' can be parsed as a Subscription ID +func ValidateSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Subscription ID +func (id SubscriptionId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s/subscriptions/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName, id.SubscriptionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Subscription ID +func (id SubscriptionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + } +} + +// String returns a human-readable description of this Subscription ID +func (id SubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + } + return fmt.Sprintf("Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription_test.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription_test.go new file mode 100644 index 00000000000..7a82d7f8bdb --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/id_subscription_test.go @@ -0,0 +1,312 @@ +package groupquotassubscriptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SubscriptionId{} + +func TestNewSubscriptionID(t *testing.T) { + id := NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } +} + +func TestFormatSubscriptionID(t *testing.T) { + actual := NewSubscriptionID("managementGroupId", "groupQuotaName", "12345678-1234-9876-4563-123456789012").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions/12345678-1234-9876-4563-123456789012" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions/12345678-1234-9876-4563-123456789012/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + } +} + +func TestParseSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptions/12345678-1234-9876-4563-123456789012/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Expected: &SubscriptionId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + } +} + +func TestSegmentsForSubscriptionId(t *testing.T) { + segments := SubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionscreateorupdate.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionscreateorupdate.go new file mode 100644 index 00000000000..dc2fd93ffe3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionscreateorupdate.go @@ -0,0 +1,71 @@ +package groupquotassubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaSubscriptionId +} + +// GroupQuotaSubscriptionsCreateOrUpdate ... +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsCreateOrUpdate(ctx context.Context, id SubscriptionId) (result GroupQuotaSubscriptionsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GroupQuotaSubscriptionsCreateOrUpdateThenPoll performs GroupQuotaSubscriptionsCreateOrUpdate then polls until it's completed +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id SubscriptionId) error { + result, err := c.GroupQuotaSubscriptionsCreateOrUpdate(ctx, id) + if err != nil { + return fmt.Errorf("performing GroupQuotaSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GroupQuotaSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsdelete.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsdelete.go new file mode 100644 index 00000000000..b3847d2515e --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsdelete.go @@ -0,0 +1,70 @@ +package groupquotassubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// GroupQuotaSubscriptionsDelete ... +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsDelete(ctx context.Context, id SubscriptionId) (result GroupQuotaSubscriptionsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GroupQuotaSubscriptionsDeleteThenPoll performs GroupQuotaSubscriptionsDelete then polls until it's completed +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsDeleteThenPoll(ctx context.Context, id SubscriptionId) error { + result, err := c.GroupQuotaSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing GroupQuotaSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GroupQuotaSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsget.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsget.go new file mode 100644 index 00000000000..83a40c59368 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsget.go @@ -0,0 +1,53 @@ +package groupquotassubscriptions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaSubscriptionId +} + +// GroupQuotaSubscriptionsGet ... +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsGet(ctx context.Context, id SubscriptionId) (result GroupQuotaSubscriptionsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GroupQuotaSubscriptionId + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionslist.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionslist.go new file mode 100644 index 00000000000..5f4f8ef6548 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionslist.go @@ -0,0 +1,105 @@ +package groupquotassubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupQuotaSubscriptionId +} + +type GroupQuotaSubscriptionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupQuotaSubscriptionId +} + +type GroupQuotaSubscriptionsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GroupQuotaSubscriptionsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GroupQuotaSubscriptionsList ... +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsList(ctx context.Context, id GroupQuotaId) (result GroupQuotaSubscriptionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GroupQuotaSubscriptionsListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GroupQuotaSubscriptionId `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GroupQuotaSubscriptionsListComplete retrieves all the results into a single object +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsListComplete(ctx context.Context, id GroupQuotaId) (GroupQuotaSubscriptionsListCompleteResult, error) { + return c.GroupQuotaSubscriptionsListCompleteMatchingPredicate(ctx, id, GroupQuotaSubscriptionIdOperationPredicate{}) +} + +// GroupQuotaSubscriptionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsListCompleteMatchingPredicate(ctx context.Context, id GroupQuotaId, predicate GroupQuotaSubscriptionIdOperationPredicate) (result GroupQuotaSubscriptionsListCompleteResult, err error) { + items := make([]GroupQuotaSubscriptionId, 0) + + resp, err := c.GroupQuotaSubscriptionsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GroupQuotaSubscriptionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsupdate.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsupdate.go new file mode 100644 index 00000000000..18a8aba407f --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/method_groupquotasubscriptionsupdate.go @@ -0,0 +1,71 @@ +package groupquotassubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaSubscriptionId +} + +// GroupQuotaSubscriptionsUpdate ... +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsUpdate(ctx context.Context, id SubscriptionId) (result GroupQuotaSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GroupQuotaSubscriptionsUpdateThenPoll performs GroupQuotaSubscriptionsUpdate then polls until it's completed +func (c GroupQuotasSubscriptionsClient) GroupQuotaSubscriptionsUpdateThenPoll(ctx context.Context, id SubscriptionId) error { + result, err := c.GroupQuotaSubscriptionsUpdate(ctx, id) + if err != nil { + return fmt.Errorf("performing GroupQuotaSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GroupQuotaSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionid.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionid.go new file mode 100644 index 00000000000..5601115032f --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionid.go @@ -0,0 +1,16 @@ +package groupquotassubscriptions + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionId struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupQuotaSubscriptionIdProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionidproperties.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionidproperties.go new file mode 100644 index 00000000000..ec12d4c2ff9 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/model_groupquotasubscriptionidproperties.go @@ -0,0 +1,9 @@ +package groupquotassubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionIdProperties struct { + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/predicates.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/predicates.go new file mode 100644 index 00000000000..90d77f05039 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/predicates.go @@ -0,0 +1,27 @@ +package groupquotassubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionIdOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupQuotaSubscriptionIdOperationPredicate) Matches(input GroupQuotaSubscriptionId) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/groupquotassubscriptions/version.go b/resource-manager/quota/2025-03-01/groupquotassubscriptions/version.go new file mode 100644 index 00000000000..57d6149de2a --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotassubscriptions/version.go @@ -0,0 +1,10 @@ +package groupquotassubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/groupquotassubscriptions/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/README.md b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/README.md new file mode 100644 index 00000000000..2aa089045e3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests` Documentation + +The `groupquotasubscriptionrequests` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests" +``` + + +### Client Initialization + +```go +client := groupquotasubscriptionrequests.NewGroupQuotaSubscriptionRequestsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupQuotaSubscriptionRequestsClient.Get` + +```go +ctx := context.TODO() +id := groupquotasubscriptionrequests.NewSubscriptionRequestID("managementGroupId", "groupQuotaName", "requestId") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupQuotaSubscriptionRequestsClient.List` + +```go +ctx := context.TODO() +id := groupquotasubscriptionrequests.NewGroupQuotaID("managementGroupId", "groupQuotaName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/client.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/client.go new file mode 100644 index 00000000000..d7566473815 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/client.go @@ -0,0 +1,26 @@ +package groupquotasubscriptionrequests + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionRequestsClient struct { + Client *resourcemanager.Client +} + +func NewGroupQuotaSubscriptionRequestsClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupQuotaSubscriptionRequestsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "groupquotasubscriptionrequests", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupQuotaSubscriptionRequestsClient: %+v", err) + } + + return &GroupQuotaSubscriptionRequestsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/constants.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/constants.go new file mode 100644 index 00000000000..22d0c400b10 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/constants.go @@ -0,0 +1,66 @@ +package groupquotasubscriptionrequests + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota.go new file mode 100644 index 00000000000..5d7efe3895c --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota.go @@ -0,0 +1,123 @@ +package groupquotasubscriptionrequests + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaId{} + +// GroupQuotaId is a struct representing the Resource ID for a Group Quota +type GroupQuotaId struct { + ManagementGroupId string + GroupQuotaName string +} + +// NewGroupQuotaID returns a new GroupQuotaId struct +func NewGroupQuotaID(managementGroupId string, groupQuotaName string) GroupQuotaId { + return GroupQuotaId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + } +} + +// ParseGroupQuotaID parses 'input' into a GroupQuotaId +func ParseGroupQuotaID(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaIDInsensitively parses 'input' case-insensitively into a GroupQuotaId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaIDInsensitively(input string) (*GroupQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + return nil +} + +// ValidateGroupQuotaID checks that 'input' can be parsed as a Group Quota ID +func ValidateGroupQuotaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota ID +func (id GroupQuotaId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota ID +func (id GroupQuotaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + } +} + +// String returns a human-readable description of this Group Quota ID +func (id GroupQuotaId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + } + return fmt.Sprintf("Group Quota (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota_test.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota_test.go new file mode 100644 index 00000000000..15913280422 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_groupquota_test.go @@ -0,0 +1,267 @@ +package groupquotasubscriptionrequests + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaId{} + +func TestNewGroupQuotaID(t *testing.T) { + id := NewGroupQuotaID("managementGroupId", "groupQuotaName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } +} + +func TestFormatGroupQuotaID(t *testing.T) { + actual := NewGroupQuotaID("managementGroupId", "groupQuotaName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestParseGroupQuotaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Expected: &GroupQuotaId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Expected: &GroupQuotaId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + } +} + +func TestSegmentsForGroupQuotaId(t *testing.T) { + segments := GroupQuotaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest.go new file mode 100644 index 00000000000..6b01fa9a040 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest.go @@ -0,0 +1,132 @@ +package groupquotasubscriptionrequests + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SubscriptionRequestId{}) +} + +var _ resourceids.ResourceId = &SubscriptionRequestId{} + +// SubscriptionRequestId is a struct representing the Resource ID for a Subscription Request +type SubscriptionRequestId struct { + ManagementGroupId string + GroupQuotaName string + RequestId string +} + +// NewSubscriptionRequestID returns a new SubscriptionRequestId struct +func NewSubscriptionRequestID(managementGroupId string, groupQuotaName string, requestId string) SubscriptionRequestId { + return SubscriptionRequestId{ + ManagementGroupId: managementGroupId, + GroupQuotaName: groupQuotaName, + RequestId: requestId, + } +} + +// ParseSubscriptionRequestID parses 'input' into a SubscriptionRequestId +func ParseSubscriptionRequestID(input string) (*SubscriptionRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSubscriptionRequestIDInsensitively parses 'input' case-insensitively into a SubscriptionRequestId +// note: this method should only be used for API response data and not user input +func ParseSubscriptionRequestIDInsensitively(input string) (*SubscriptionRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SubscriptionRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.RequestId, ok = input.Parsed["requestId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "requestId", input) + } + + return nil +} + +// ValidateSubscriptionRequestID checks that 'input' can be parsed as a Subscription Request ID +func ValidateSubscriptionRequestID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSubscriptionRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Subscription Request ID +func (id SubscriptionRequestId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Quota/groupQuotas/%s/subscriptionRequests/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.GroupQuotaName, id.RequestId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Subscription Request ID +func (id SubscriptionRequestId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticSubscriptionRequests", "subscriptionRequests", "subscriptionRequests"), + resourceids.UserSpecifiedSegment("requestId", "requestId"), + } +} + +// String returns a human-readable description of this Subscription Request ID +func (id SubscriptionRequestId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Request: %q", id.RequestId), + } + return fmt.Sprintf("Subscription Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest_test.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest_test.go new file mode 100644 index 00000000000..2aa807bd0a8 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/id_subscriptionrequest_test.go @@ -0,0 +1,312 @@ +package groupquotasubscriptionrequests + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SubscriptionRequestId{} + +func TestNewSubscriptionRequestID(t *testing.T) { + id := NewSubscriptionRequestID("managementGroupId", "groupQuotaName", "requestId") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.RequestId != "requestId" { + t.Fatalf("Expected %q but got %q for Segment 'RequestId'", id.RequestId, "requestId") + } +} + +func TestFormatSubscriptionRequestID(t *testing.T) { + actual := NewSubscriptionRequestID("managementGroupId", "groupQuotaName", "requestId").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests/requestId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSubscriptionRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests/requestId", + Expected: &SubscriptionRequestId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + RequestId: "requestId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests/requestId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionRequestID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.RequestId != v.Expected.RequestId { + t.Fatalf("Expected %q but got %q for RequestId", v.Expected.RequestId, actual.RequestId) + } + + } +} + +func TestParseSubscriptionRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests/requestId", + Expected: &SubscriptionRequestId{ + ManagementGroupId: "managementGroupId", + GroupQuotaName: "groupQuotaName", + RequestId: "requestId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/providers/Microsoft.Quota/groupQuotas/groupQuotaName/subscriptionRequests/requestId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNrEqUeStS/rEqUeStId", + Expected: &SubscriptionRequestId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + GroupQuotaName: "gRoUpQuOtAnAmE", + RequestId: "rEqUeStId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/sUbScRiPtIoNrEqUeStS/rEqUeStId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionRequestIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.RequestId != v.Expected.RequestId { + t.Fatalf("Expected %q but got %q for RequestId", v.Expected.RequestId, actual.RequestId) + } + + } +} + +func TestSegmentsForSubscriptionRequestId(t *testing.T) { + segments := SubscriptionRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SubscriptionRequestId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_get.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_get.go new file mode 100644 index 00000000000..582012fddde --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_get.go @@ -0,0 +1,53 @@ +package groupquotasubscriptionrequests + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupQuotaSubscriptionRequestStatus +} + +// Get ... +func (c GroupQuotaSubscriptionRequestsClient) Get(ctx context.Context, id SubscriptionRequestId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GroupQuotaSubscriptionRequestStatus + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_list.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_list.go new file mode 100644 index 00000000000..81935456f29 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/method_list.go @@ -0,0 +1,105 @@ +package groupquotasubscriptionrequests + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupQuotaSubscriptionRequestStatus +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupQuotaSubscriptionRequestStatus +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c GroupQuotaSubscriptionRequestsClient) List(ctx context.Context, id GroupQuotaId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptionRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GroupQuotaSubscriptionRequestStatus `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c GroupQuotaSubscriptionRequestsClient) ListComplete(ctx context.Context, id GroupQuotaId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, GroupQuotaSubscriptionRequestStatusOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupQuotaSubscriptionRequestsClient) ListCompleteMatchingPredicate(ctx context.Context, id GroupQuotaId, predicate GroupQuotaSubscriptionRequestStatusOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GroupQuotaSubscriptionRequestStatus, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatus.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatus.go new file mode 100644 index 00000000000..a5fa6483bf7 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatus.go @@ -0,0 +1,16 @@ +package groupquotasubscriptionrequests + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionRequestStatus struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupQuotaSubscriptionRequestStatusProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatusproperties.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatusproperties.go new file mode 100644 index 00000000000..1dc945ae0b7 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/model_groupquotasubscriptionrequeststatusproperties.go @@ -0,0 +1,28 @@ +package groupquotasubscriptionrequests + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionRequestStatusProperties struct { + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + RequestSubmitTime *string `json:"requestSubmitTime,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} + +func (o *GroupQuotaSubscriptionRequestStatusProperties) GetRequestSubmitTimeAsTime() (*time.Time, error) { + if o.RequestSubmitTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RequestSubmitTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GroupQuotaSubscriptionRequestStatusProperties) SetRequestSubmitTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RequestSubmitTime = &formatted +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/predicates.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/predicates.go new file mode 100644 index 00000000000..175dff10c81 --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/predicates.go @@ -0,0 +1,27 @@ +package groupquotasubscriptionrequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionRequestStatusOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupQuotaSubscriptionRequestStatusOperationPredicate) Matches(input GroupQuotaSubscriptionRequestStatus) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/version.go b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/version.go new file mode 100644 index 00000000000..77663e9a90a --- /dev/null +++ b/resource-manager/quota/2025-03-01/groupquotasubscriptionrequests/version.go @@ -0,0 +1,10 @@ +package groupquotasubscriptionrequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/groupquotasubscriptionrequests/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/README.md b/resource-manager/quota/2025-03-01/quotainformation/README.md new file mode 100644 index 00000000000..3c28ff072ef --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/README.md @@ -0,0 +1,88 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotainformation` Documentation + +The `quotainformation` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotainformation" +``` + + +### Client Initialization + +```go +client := quotainformation.NewQuotaInformationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QuotaInformationClient.QuotaCreateOrUpdate` + +```go +ctx := context.TODO() +id := quotainformation.NewScopedQuotaID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaName") + +payload := quotainformation.CurrentQuotaLimitBase{ + // ... +} + + +if err := client.QuotaCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `QuotaInformationClient.QuotaGet` + +```go +ctx := context.TODO() +id := quotainformation.NewScopedQuotaID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaName") + +read, err := client.QuotaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QuotaInformationClient.QuotaList` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.QuotaList(ctx, id)` can be used to do batched pagination +items, err := client.QuotaListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `QuotaInformationClient.QuotaUpdate` + +```go +ctx := context.TODO() +id := quotainformation.NewScopedQuotaID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaName") + +payload := quotainformation.CurrentQuotaLimitBase{ + // ... +} + + +if err := client.QuotaUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/quota/2025-03-01/quotainformation/client.go b/resource-manager/quota/2025-03-01/quotainformation/client.go new file mode 100644 index 00000000000..54e760f54cf --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/client.go @@ -0,0 +1,26 @@ +package quotainformation + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaInformationClient struct { + Client *resourcemanager.Client +} + +func NewQuotaInformationClientWithBaseURI(sdkApi sdkEnv.Api) (*QuotaInformationClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "quotainformation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QuotaInformationClient: %+v", err) + } + + return &QuotaInformationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/constants.go b/resource-manager/quota/2025-03-01/quotainformation/constants.go new file mode 100644 index 00000000000..7356e61b418 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/constants.go @@ -0,0 +1,89 @@ +package quotainformation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LimitType string + +const ( + LimitTypeLimitValue LimitType = "LimitValue" +) + +func PossibleValuesForLimitType() []string { + return []string{ + string(LimitTypeLimitValue), + } +} + +func (s *LimitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLimitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLimitType(input string) (*LimitType, error) { + vals := map[string]LimitType{ + "limitvalue": LimitTypeLimitValue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LimitType(input) + return &out, nil +} + +type QuotaLimitTypes string + +const ( + QuotaLimitTypesIndependent QuotaLimitTypes = "Independent" + QuotaLimitTypesShared QuotaLimitTypes = "Shared" +) + +func PossibleValuesForQuotaLimitTypes() []string { + return []string{ + string(QuotaLimitTypesIndependent), + string(QuotaLimitTypesShared), + } +} + +func (s *QuotaLimitTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQuotaLimitTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQuotaLimitTypes(input string) (*QuotaLimitTypes, error) { + vals := map[string]QuotaLimitTypes{ + "independent": QuotaLimitTypesIndependent, + "shared": QuotaLimitTypesShared, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QuotaLimitTypes(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota.go b/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota.go new file mode 100644 index 00000000000..079fc2ee8d9 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota.go @@ -0,0 +1,120 @@ +package quotainformation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedQuotaId{}) +} + +var _ resourceids.ResourceId = &ScopedQuotaId{} + +// ScopedQuotaId is a struct representing the Resource ID for a Scoped Quota +type ScopedQuotaId struct { + Scope string + QuotaName string +} + +// NewScopedQuotaID returns a new ScopedQuotaId struct +func NewScopedQuotaID(scope string, quotaName string) ScopedQuotaId { + return ScopedQuotaId{ + Scope: scope, + QuotaName: quotaName, + } +} + +// ParseScopedQuotaID parses 'input' into a ScopedQuotaId +func ParseScopedQuotaID(input string) (*ScopedQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedQuotaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedQuotaIDInsensitively parses 'input' case-insensitively into a ScopedQuotaId +// note: this method should only be used for API response data and not user input +func ParseScopedQuotaIDInsensitively(input string) (*ScopedQuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedQuotaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedQuotaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedQuotaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.QuotaName, ok = input.Parsed["quotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaName", input) + } + + return nil +} + +// ValidateScopedQuotaID checks that 'input' can be parsed as a Scoped Quota ID +func ValidateScopedQuotaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedQuotaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Quota ID +func (id ScopedQuotaId) ID() string { + fmtString := "/%s/providers/Microsoft.Quota/quotas/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.QuotaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Quota ID +func (id ScopedQuotaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticQuotas", "quotas", "quotas"), + resourceids.UserSpecifiedSegment("quotaName", "quotaName"), + } +} + +// String returns a human-readable description of this Scoped Quota ID +func (id ScopedQuotaId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Quota Name: %q", id.QuotaName), + } + return fmt.Sprintf("Scoped Quota (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota_test.go b/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota_test.go new file mode 100644 index 00000000000..23a23ed14d4 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/id_scopedquota_test.go @@ -0,0 +1,222 @@ +package quotainformation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedQuotaId{} + +func TestNewScopedQuotaID(t *testing.T) { + id := NewScopedQuotaID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.QuotaName != "quotaName" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaName'", id.QuotaName, "quotaName") + } +} + +func TestFormatScopedQuotaID(t *testing.T) { + actual := NewScopedQuotaID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas/quotaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedQuotaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas/quotaName", + Expected: &ScopedQuotaId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + QuotaName: "quotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas/quotaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedQuotaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.QuotaName != v.Expected.QuotaName { + t.Fatalf("Expected %q but got %q for QuotaName", v.Expected.QuotaName, actual.QuotaName) + } + + } +} + +func TestParseScopedQuotaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedQuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas/quotaName", + Expected: &ScopedQuotaId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + QuotaName: "quotaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotas/quotaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaS/qUoTaNaMe", + Expected: &ScopedQuotaId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + QuotaName: "qUoTaNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaS/qUoTaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedQuotaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.QuotaName != v.Expected.QuotaName { + t.Fatalf("Expected %q but got %q for QuotaName", v.Expected.QuotaName, actual.QuotaName) + } + + } +} + +func TestSegmentsForScopedQuotaId(t *testing.T) { + segments := ScopedQuotaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedQuotaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/method_quotacreateorupdate.go b/resource-manager/quota/2025-03-01/quotainformation/method_quotacreateorupdate.go new file mode 100644 index 00000000000..163788c9c04 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/method_quotacreateorupdate.go @@ -0,0 +1,75 @@ +package quotainformation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CurrentQuotaLimitBase +} + +// QuotaCreateOrUpdate ... +func (c QuotaInformationClient) QuotaCreateOrUpdate(ctx context.Context, id ScopedQuotaId, input CurrentQuotaLimitBase) (result QuotaCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// QuotaCreateOrUpdateThenPoll performs QuotaCreateOrUpdate then polls until it's completed +func (c QuotaInformationClient) QuotaCreateOrUpdateThenPoll(ctx context.Context, id ScopedQuotaId, input CurrentQuotaLimitBase) error { + result, err := c.QuotaCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing QuotaCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after QuotaCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/method_quotaget.go b/resource-manager/quota/2025-03-01/quotainformation/method_quotaget.go new file mode 100644 index 00000000000..d0648912ced --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/method_quotaget.go @@ -0,0 +1,53 @@ +package quotainformation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CurrentQuotaLimitBase +} + +// QuotaGet ... +func (c QuotaInformationClient) QuotaGet(ctx context.Context, id ScopedQuotaId) (result QuotaGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CurrentQuotaLimitBase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/method_quotalist.go b/resource-manager/quota/2025-03-01/quotainformation/method_quotalist.go new file mode 100644 index 00000000000..21be7228e5b --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/method_quotalist.go @@ -0,0 +1,106 @@ +package quotainformation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CurrentQuotaLimitBase +} + +type QuotaListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CurrentQuotaLimitBase +} + +type QuotaListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *QuotaListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// QuotaList ... +func (c QuotaInformationClient) QuotaList(ctx context.Context, id commonids.ScopeId) (result QuotaListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &QuotaListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Quota/quotas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CurrentQuotaLimitBase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// QuotaListComplete retrieves all the results into a single object +func (c QuotaInformationClient) QuotaListComplete(ctx context.Context, id commonids.ScopeId) (QuotaListCompleteResult, error) { + return c.QuotaListCompleteMatchingPredicate(ctx, id, CurrentQuotaLimitBaseOperationPredicate{}) +} + +// QuotaListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QuotaInformationClient) QuotaListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate CurrentQuotaLimitBaseOperationPredicate) (result QuotaListCompleteResult, err error) { + items := make([]CurrentQuotaLimitBase, 0) + + resp, err := c.QuotaList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = QuotaListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/method_quotaupdate.go b/resource-manager/quota/2025-03-01/quotainformation/method_quotaupdate.go new file mode 100644 index 00000000000..81c0355a459 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/method_quotaupdate.go @@ -0,0 +1,75 @@ +package quotainformation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CurrentQuotaLimitBase +} + +// QuotaUpdate ... +func (c QuotaInformationClient) QuotaUpdate(ctx context.Context, id ScopedQuotaId, input CurrentQuotaLimitBase) (result QuotaUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// QuotaUpdateThenPoll performs QuotaUpdate then polls until it's completed +func (c QuotaInformationClient) QuotaUpdateThenPoll(ctx context.Context, id ScopedQuotaId, input CurrentQuotaLimitBase) error { + result, err := c.QuotaUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing QuotaUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after QuotaUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/model_currentquotalimitbase.go b/resource-manager/quota/2025-03-01/quotainformation/model_currentquotalimitbase.go new file mode 100644 index 00000000000..340824b8f29 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/model_currentquotalimitbase.go @@ -0,0 +1,11 @@ +package quotainformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentQuotaLimitBase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QuotaProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/model_limitjsonobject.go b/resource-manager/quota/2025-03-01/quotainformation/model_limitjsonobject.go new file mode 100644 index 00000000000..82a46c1b877 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/model_limitjsonobject.go @@ -0,0 +1,75 @@ +package quotainformation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LimitJsonObject interface { + LimitJsonObject() BaseLimitJsonObjectImpl +} + +var _ LimitJsonObject = BaseLimitJsonObjectImpl{} + +type BaseLimitJsonObjectImpl struct { + LimitObjectType LimitType `json:"limitObjectType"` +} + +func (s BaseLimitJsonObjectImpl) LimitJsonObject() BaseLimitJsonObjectImpl { + return s +} + +var _ LimitJsonObject = RawLimitJsonObjectImpl{} + +// RawLimitJsonObjectImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawLimitJsonObjectImpl struct { + limitJsonObject BaseLimitJsonObjectImpl + Type string + Values map[string]interface{} +} + +func (s RawLimitJsonObjectImpl) LimitJsonObject() BaseLimitJsonObjectImpl { + return s.limitJsonObject +} + +func UnmarshalLimitJsonObjectImplementation(input []byte) (LimitJsonObject, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling LimitJsonObject into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["limitObjectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "LimitValue") { + var out LimitObject + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LimitObject: %+v", err) + } + return out, nil + } + + var parent BaseLimitJsonObjectImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseLimitJsonObjectImpl: %+v", err) + } + + return RawLimitJsonObjectImpl{ + limitJsonObject: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/model_limitobject.go b/resource-manager/quota/2025-03-01/quotainformation/model_limitobject.go new file mode 100644 index 00000000000..151ec263df3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/model_limitobject.go @@ -0,0 +1,51 @@ +package quotainformation + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ LimitJsonObject = LimitObject{} + +type LimitObject struct { + LimitType *QuotaLimitTypes `json:"limitType,omitempty"` + Value int64 `json:"value"` + + // Fields inherited from LimitJsonObject + + LimitObjectType LimitType `json:"limitObjectType"` +} + +func (s LimitObject) LimitJsonObject() BaseLimitJsonObjectImpl { + return BaseLimitJsonObjectImpl{ + LimitObjectType: s.LimitObjectType, + } +} + +var _ json.Marshaler = LimitObject{} + +func (s LimitObject) MarshalJSON() ([]byte, error) { + type wrapper LimitObject + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LimitObject: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LimitObject: %+v", err) + } + + decoded["limitObjectType"] = "LimitValue" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LimitObject: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/model_quotaproperties.go b/resource-manager/quota/2025-03-01/quotainformation/model_quotaproperties.go new file mode 100644 index 00000000000..b870a3e5165 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/model_quotaproperties.go @@ -0,0 +1,57 @@ +package quotainformation + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaProperties struct { + IsQuotaApplicable *bool `json:"isQuotaApplicable,omitempty"` + Limit LimitJsonObject `json:"limit"` + Name *ResourceName `json:"name,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +var _ json.Unmarshaler = &QuotaProperties{} + +func (s *QuotaProperties) UnmarshalJSON(bytes []byte) error { + var decoded struct { + IsQuotaApplicable *bool `json:"isQuotaApplicable,omitempty"` + Name *ResourceName `json:"name,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *string `json:"unit,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.IsQuotaApplicable = decoded.IsQuotaApplicable + s.Name = decoded.Name + s.Properties = decoded.Properties + s.QuotaPeriod = decoded.QuotaPeriod + s.ResourceType = decoded.ResourceType + s.Unit = decoded.Unit + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling QuotaProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["limit"]; ok { + impl, err := UnmarshalLimitJsonObjectImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Limit' for 'QuotaProperties': %+v", err) + } + s.Limit = impl + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/model_resourcename.go b/resource-manager/quota/2025-03-01/quotainformation/model_resourcename.go new file mode 100644 index 00000000000..ee2e61891d1 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/model_resourcename.go @@ -0,0 +1,9 @@ +package quotainformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/predicates.go b/resource-manager/quota/2025-03-01/quotainformation/predicates.go new file mode 100644 index 00000000000..0fd73994e6a --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/predicates.go @@ -0,0 +1,27 @@ +package quotainformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentQuotaLimitBaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CurrentQuotaLimitBaseOperationPredicate) Matches(input CurrentQuotaLimitBase) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/quotainformation/version.go b/resource-manager/quota/2025-03-01/quotainformation/version.go new file mode 100644 index 00000000000..c112a38f884 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotainformation/version.go @@ -0,0 +1,10 @@ +package quotainformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/quotainformation/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/README.md b/resource-manager/quota/2025-03-01/quotarequests/README.md new file mode 100644 index 00000000000..9e96f4216ba --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotarequests` Documentation + +The `quotarequests` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/quotarequests" +``` + + +### Client Initialization + +```go +client := quotarequests.NewQuotaRequestsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QuotaRequestsClient.TatusGet` + +```go +ctx := context.TODO() +id := quotarequests.NewScopedQuotaRequestID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaRequestName") + +read, err := client.TatusGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QuotaRequestsClient.TatusList` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.TatusList(ctx, id, quotarequests.DefaultTatusListOperationOptions())` can be used to do batched pagination +items, err := client.TatusListComplete(ctx, id, quotarequests.DefaultTatusListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/quota/2025-03-01/quotarequests/client.go b/resource-manager/quota/2025-03-01/quotarequests/client.go new file mode 100644 index 00000000000..19cbb5ad4c2 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/client.go @@ -0,0 +1,26 @@ +package quotarequests + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaRequestsClient struct { + Client *resourcemanager.Client +} + +func NewQuotaRequestsClientWithBaseURI(sdkApi sdkEnv.Api) (*QuotaRequestsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "quotarequests", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QuotaRequestsClient: %+v", err) + } + + return &QuotaRequestsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/constants.go b/resource-manager/quota/2025-03-01/quotarequests/constants.go new file mode 100644 index 00000000000..58f48e08d7f --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/constants.go @@ -0,0 +1,139 @@ +package quotarequests + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LimitType string + +const ( + LimitTypeLimitValue LimitType = "LimitValue" +) + +func PossibleValuesForLimitType() []string { + return []string{ + string(LimitTypeLimitValue), + } +} + +func (s *LimitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLimitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLimitType(input string) (*LimitType, error) { + vals := map[string]LimitType{ + "limitvalue": LimitTypeLimitValue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LimitType(input) + return &out, nil +} + +type QuotaLimitTypes string + +const ( + QuotaLimitTypesIndependent QuotaLimitTypes = "Independent" + QuotaLimitTypesShared QuotaLimitTypes = "Shared" +) + +func PossibleValuesForQuotaLimitTypes() []string { + return []string{ + string(QuotaLimitTypesIndependent), + string(QuotaLimitTypesShared), + } +} + +func (s *QuotaLimitTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQuotaLimitTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQuotaLimitTypes(input string) (*QuotaLimitTypes, error) { + vals := map[string]QuotaLimitTypes{ + "independent": QuotaLimitTypesIndependent, + "shared": QuotaLimitTypesShared, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QuotaLimitTypes(input) + return &out, nil +} + +type QuotaRequestState string + +const ( + QuotaRequestStateAccepted QuotaRequestState = "Accepted" + QuotaRequestStateFailed QuotaRequestState = "Failed" + QuotaRequestStateInProgress QuotaRequestState = "InProgress" + QuotaRequestStateInvalid QuotaRequestState = "Invalid" + QuotaRequestStateSucceeded QuotaRequestState = "Succeeded" +) + +func PossibleValuesForQuotaRequestState() []string { + return []string{ + string(QuotaRequestStateAccepted), + string(QuotaRequestStateFailed), + string(QuotaRequestStateInProgress), + string(QuotaRequestStateInvalid), + string(QuotaRequestStateSucceeded), + } +} + +func (s *QuotaRequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQuotaRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQuotaRequestState(input string) (*QuotaRequestState, error) { + vals := map[string]QuotaRequestState{ + "accepted": QuotaRequestStateAccepted, + "failed": QuotaRequestStateFailed, + "inprogress": QuotaRequestStateInProgress, + "invalid": QuotaRequestStateInvalid, + "succeeded": QuotaRequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QuotaRequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest.go b/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest.go new file mode 100644 index 00000000000..d39157da9d8 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest.go @@ -0,0 +1,120 @@ +package quotarequests + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedQuotaRequestId{}) +} + +var _ resourceids.ResourceId = &ScopedQuotaRequestId{} + +// ScopedQuotaRequestId is a struct representing the Resource ID for a Scoped Quota Request +type ScopedQuotaRequestId struct { + Scope string + QuotaRequestName string +} + +// NewScopedQuotaRequestID returns a new ScopedQuotaRequestId struct +func NewScopedQuotaRequestID(scope string, quotaRequestName string) ScopedQuotaRequestId { + return ScopedQuotaRequestId{ + Scope: scope, + QuotaRequestName: quotaRequestName, + } +} + +// ParseScopedQuotaRequestID parses 'input' into a ScopedQuotaRequestId +func ParseScopedQuotaRequestID(input string) (*ScopedQuotaRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedQuotaRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedQuotaRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedQuotaRequestIDInsensitively parses 'input' case-insensitively into a ScopedQuotaRequestId +// note: this method should only be used for API response data and not user input +func ParseScopedQuotaRequestIDInsensitively(input string) (*ScopedQuotaRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedQuotaRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedQuotaRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedQuotaRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.QuotaRequestName, ok = input.Parsed["quotaRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaRequestName", input) + } + + return nil +} + +// ValidateScopedQuotaRequestID checks that 'input' can be parsed as a Scoped Quota Request ID +func ValidateScopedQuotaRequestID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedQuotaRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Quota Request ID +func (id ScopedQuotaRequestId) ID() string { + fmtString := "/%s/providers/Microsoft.Quota/quotaRequests/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.QuotaRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Quota Request ID +func (id ScopedQuotaRequestId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticQuotaRequests", "quotaRequests", "quotaRequests"), + resourceids.UserSpecifiedSegment("quotaRequestName", "quotaRequestName"), + } +} + +// String returns a human-readable description of this Scoped Quota Request ID +func (id ScopedQuotaRequestId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Quota Request Name: %q", id.QuotaRequestName), + } + return fmt.Sprintf("Scoped Quota Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest_test.go b/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest_test.go new file mode 100644 index 00000000000..ad4db9cfefe --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/id_scopedquotarequest_test.go @@ -0,0 +1,222 @@ +package quotarequests + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedQuotaRequestId{} + +func TestNewScopedQuotaRequestID(t *testing.T) { + id := NewScopedQuotaRequestID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaRequestName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.QuotaRequestName != "quotaRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaRequestName'", id.QuotaRequestName, "quotaRequestName") + } +} + +func TestFormatScopedQuotaRequestID(t *testing.T) { + actual := NewScopedQuotaRequestID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "quotaRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests/quotaRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedQuotaRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedQuotaRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests/quotaRequestName", + Expected: &ScopedQuotaRequestId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + QuotaRequestName: "quotaRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests/quotaRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedQuotaRequestID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.QuotaRequestName != v.Expected.QuotaRequestName { + t.Fatalf("Expected %q but got %q for QuotaRequestName", v.Expected.QuotaRequestName, actual.QuotaRequestName) + } + + } +} + +func TestParseScopedQuotaRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedQuotaRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests/quotaRequestName", + Expected: &ScopedQuotaRequestId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + QuotaRequestName: "quotaRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/quotaRequests/quotaRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaReQuEsTs/qUoTaReQuEsTnAmE", + Expected: &ScopedQuotaRequestId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + QuotaRequestName: "qUoTaReQuEsTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/qUoTaReQuEsTs/qUoTaReQuEsTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedQuotaRequestIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.QuotaRequestName != v.Expected.QuotaRequestName { + t.Fatalf("Expected %q but got %q for QuotaRequestName", v.Expected.QuotaRequestName, actual.QuotaRequestName) + } + + } +} + +func TestSegmentsForScopedQuotaRequestId(t *testing.T) { + segments := ScopedQuotaRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedQuotaRequestId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/method_tatusget.go b/resource-manager/quota/2025-03-01/quotarequests/method_tatusget.go new file mode 100644 index 00000000000..e83b8aeee99 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/method_tatusget.go @@ -0,0 +1,53 @@ +package quotarequests + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TatusGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *QuotaRequestDetails +} + +// TatusGet ... +func (c QuotaRequestsClient) TatusGet(ctx context.Context, id ScopedQuotaRequestId) (result TatusGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model QuotaRequestDetails + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/method_tatuslist.go b/resource-manager/quota/2025-03-01/quotarequests/method_tatuslist.go new file mode 100644 index 00000000000..bb398db7b64 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/method_tatuslist.go @@ -0,0 +1,139 @@ +package quotarequests + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TatusListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]QuotaRequestDetails +} + +type TatusListCompleteResult struct { + LatestHttpResponse *http.Response + Items []QuotaRequestDetails +} + +type TatusListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultTatusListOperationOptions() TatusListOperationOptions { + return TatusListOperationOptions{} +} + +func (o TatusListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TatusListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o TatusListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type TatusListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *TatusListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// TatusList ... +func (c QuotaRequestsClient) TatusList(ctx context.Context, id commonids.ScopeId, options TatusListOperationOptions) (result TatusListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &TatusListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Quota/quotaRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]QuotaRequestDetails `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TatusListComplete retrieves all the results into a single object +func (c QuotaRequestsClient) TatusListComplete(ctx context.Context, id commonids.ScopeId, options TatusListOperationOptions) (TatusListCompleteResult, error) { + return c.TatusListCompleteMatchingPredicate(ctx, id, options, QuotaRequestDetailsOperationPredicate{}) +} + +// TatusListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QuotaRequestsClient) TatusListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options TatusListOperationOptions, predicate QuotaRequestDetailsOperationPredicate) (result TatusListCompleteResult, err error) { + items := make([]QuotaRequestDetails, 0) + + resp, err := c.TatusList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TatusListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_limitjsonobject.go b/resource-manager/quota/2025-03-01/quotarequests/model_limitjsonobject.go new file mode 100644 index 00000000000..7bede025d0f --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_limitjsonobject.go @@ -0,0 +1,75 @@ +package quotarequests + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LimitJsonObject interface { + LimitJsonObject() BaseLimitJsonObjectImpl +} + +var _ LimitJsonObject = BaseLimitJsonObjectImpl{} + +type BaseLimitJsonObjectImpl struct { + LimitObjectType LimitType `json:"limitObjectType"` +} + +func (s BaseLimitJsonObjectImpl) LimitJsonObject() BaseLimitJsonObjectImpl { + return s +} + +var _ LimitJsonObject = RawLimitJsonObjectImpl{} + +// RawLimitJsonObjectImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawLimitJsonObjectImpl struct { + limitJsonObject BaseLimitJsonObjectImpl + Type string + Values map[string]interface{} +} + +func (s RawLimitJsonObjectImpl) LimitJsonObject() BaseLimitJsonObjectImpl { + return s.limitJsonObject +} + +func UnmarshalLimitJsonObjectImplementation(input []byte) (LimitJsonObject, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling LimitJsonObject into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["limitObjectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "LimitValue") { + var out LimitObject + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LimitObject: %+v", err) + } + return out, nil + } + + var parent BaseLimitJsonObjectImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseLimitJsonObjectImpl: %+v", err) + } + + return RawLimitJsonObjectImpl{ + limitJsonObject: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_limitobject.go b/resource-manager/quota/2025-03-01/quotarequests/model_limitobject.go new file mode 100644 index 00000000000..c278dd2f7c5 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_limitobject.go @@ -0,0 +1,51 @@ +package quotarequests + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ LimitJsonObject = LimitObject{} + +type LimitObject struct { + LimitType *QuotaLimitTypes `json:"limitType,omitempty"` + Value int64 `json:"value"` + + // Fields inherited from LimitJsonObject + + LimitObjectType LimitType `json:"limitObjectType"` +} + +func (s LimitObject) LimitJsonObject() BaseLimitJsonObjectImpl { + return BaseLimitJsonObjectImpl{ + LimitObjectType: s.LimitObjectType, + } +} + +var _ json.Marshaler = LimitObject{} + +func (s LimitObject) MarshalJSON() ([]byte, error) { + type wrapper LimitObject + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LimitObject: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LimitObject: %+v", err) + } + + decoded["limitObjectType"] = "LimitValue" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LimitObject: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestdetails.go b/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestdetails.go new file mode 100644 index 00000000000..3c2c2a81119 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestdetails.go @@ -0,0 +1,11 @@ +package quotarequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaRequestDetails struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QuotaRequestProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestproperties.go b/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestproperties.go new file mode 100644 index 00000000000..98e28080d01 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_quotarequestproperties.go @@ -0,0 +1,30 @@ +package quotarequests + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaRequestProperties struct { + Error *ServiceErrorDetail `json:"error,omitempty"` + Message *string `json:"message,omitempty"` + ProvisioningState *QuotaRequestState `json:"provisioningState,omitempty"` + RequestSubmitTime *string `json:"requestSubmitTime,omitempty"` + Value *[]SubRequest `json:"value,omitempty"` +} + +func (o *QuotaRequestProperties) GetRequestSubmitTimeAsTime() (*time.Time, error) { + if o.RequestSubmitTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RequestSubmitTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaRequestProperties) SetRequestSubmitTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RequestSubmitTime = &formatted +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_resourcename.go b/resource-manager/quota/2025-03-01/quotarequests/model_resourcename.go new file mode 100644 index 00000000000..6dac9a64f0f --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_resourcename.go @@ -0,0 +1,9 @@ +package quotarequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_serviceerrordetail.go b/resource-manager/quota/2025-03-01/quotarequests/model_serviceerrordetail.go new file mode 100644 index 00000000000..caabf8db89b --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_serviceerrordetail.go @@ -0,0 +1,9 @@ +package quotarequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/model_subrequest.go b/resource-manager/quota/2025-03-01/quotarequests/model_subrequest.go new file mode 100644 index 00000000000..515e7cbff31 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/model_subrequest.go @@ -0,0 +1,57 @@ +package quotarequests + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubRequest struct { + Limit LimitJsonObject `json:"limit"` + Message *string `json:"message,omitempty"` + Name *ResourceName `json:"name,omitempty"` + ProvisioningState *QuotaRequestState `json:"provisioningState,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + SubRequestId *string `json:"subRequestId,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +var _ json.Unmarshaler = &SubRequest{} + +func (s *SubRequest) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Message *string `json:"message,omitempty"` + Name *ResourceName `json:"name,omitempty"` + ProvisioningState *QuotaRequestState `json:"provisioningState,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + SubRequestId *string `json:"subRequestId,omitempty"` + Unit *string `json:"unit,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Message = decoded.Message + s.Name = decoded.Name + s.ProvisioningState = decoded.ProvisioningState + s.ResourceType = decoded.ResourceType + s.SubRequestId = decoded.SubRequestId + s.Unit = decoded.Unit + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SubRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["limit"]; ok { + impl, err := UnmarshalLimitJsonObjectImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Limit' for 'SubRequest': %+v", err) + } + s.Limit = impl + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/predicates.go b/resource-manager/quota/2025-03-01/quotarequests/predicates.go new file mode 100644 index 00000000000..44e2ae87780 --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/predicates.go @@ -0,0 +1,27 @@ +package quotarequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaRequestDetailsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p QuotaRequestDetailsOperationPredicate) Matches(input QuotaRequestDetails) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/quotarequests/version.go b/resource-manager/quota/2025-03-01/quotarequests/version.go new file mode 100644 index 00000000000..7218a489bce --- /dev/null +++ b/resource-manager/quota/2025-03-01/quotarequests/version.go @@ -0,0 +1,10 @@ +package quotarequests + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/quotarequests/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/README.md b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/README.md new file mode 100644 index 00000000000..bd07b0c267f --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocation` Documentation + +The `subscriptionquotaallocation` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocation" +``` + + +### Client Initialization + +```go +client := subscriptionquotaallocation.NewSubscriptionQuotaAllocationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionQuotaAllocationClient.GroupQuotaSubscriptionAllocationList` + +```go +ctx := context.TODO() +id := subscriptionquotaallocation.NewQuotaAllocationID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "quotaAllocationName") + +read, err := client.GroupQuotaSubscriptionAllocationList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionQuotaAllocationClient.GroupQuotaSubscriptionAllocationRequestUpdate` + +```go +ctx := context.TODO() +id := subscriptionquotaallocation.NewQuotaAllocationID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "quotaAllocationName") + +payload := subscriptionquotaallocation.SubscriptionQuotaAllocationsList{ + // ... +} + + +if err := client.GroupQuotaSubscriptionAllocationRequestUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/client.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/client.go new file mode 100644 index 00000000000..a61d70c7f36 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/client.go @@ -0,0 +1,26 @@ +package subscriptionquotaallocation + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaAllocationClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionQuotaAllocationClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionQuotaAllocationClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "subscriptionquotaallocation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionQuotaAllocationClient: %+v", err) + } + + return &SubscriptionQuotaAllocationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/constants.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/constants.go new file mode 100644 index 00000000000..6f0e6c6b822 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/constants.go @@ -0,0 +1,66 @@ +package subscriptionquotaallocation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation.go new file mode 100644 index 00000000000..235c8be62f3 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation.go @@ -0,0 +1,150 @@ +package subscriptionquotaallocation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QuotaAllocationId{}) +} + +var _ resourceids.ResourceId = &QuotaAllocationId{} + +// QuotaAllocationId is a struct representing the Resource ID for a Quota Allocation +type QuotaAllocationId struct { + ManagementGroupId string + SubscriptionId string + GroupQuotaName string + ResourceProviderName string + QuotaAllocationName string +} + +// NewQuotaAllocationID returns a new QuotaAllocationId struct +func NewQuotaAllocationID(managementGroupId string, subscriptionId string, groupQuotaName string, resourceProviderName string, quotaAllocationName string) QuotaAllocationId { + return QuotaAllocationId{ + ManagementGroupId: managementGroupId, + SubscriptionId: subscriptionId, + GroupQuotaName: groupQuotaName, + ResourceProviderName: resourceProviderName, + QuotaAllocationName: quotaAllocationName, + } +} + +// ParseQuotaAllocationID parses 'input' into a QuotaAllocationId +func ParseQuotaAllocationID(input string) (*QuotaAllocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaAllocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaAllocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQuotaAllocationIDInsensitively parses 'input' case-insensitively into a QuotaAllocationId +// note: this method should only be used for API response data and not user input +func ParseQuotaAllocationIDInsensitively(input string) (*QuotaAllocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaAllocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaAllocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QuotaAllocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.ResourceProviderName, ok = input.Parsed["resourceProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceProviderName", input) + } + + if id.QuotaAllocationName, ok = input.Parsed["quotaAllocationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaAllocationName", input) + } + + return nil +} + +// ValidateQuotaAllocationID checks that 'input' can be parsed as a Quota Allocation ID +func ValidateQuotaAllocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseQuotaAllocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Quota Allocation ID +func (id QuotaAllocationId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/subscriptions/%s/providers/Microsoft.Quota/groupQuotas/%s/resourceProviders/%s/quotaAllocations/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.SubscriptionId, id.GroupQuotaName, id.ResourceProviderName, id.QuotaAllocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Quota Allocation ID +func (id QuotaAllocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticResourceProviders", "resourceProviders", "resourceProviders"), + resourceids.UserSpecifiedSegment("resourceProviderName", "resourceProviderName"), + resourceids.StaticSegment("staticQuotaAllocations", "quotaAllocations", "quotaAllocations"), + resourceids.UserSpecifiedSegment("quotaAllocationName", "quotaAllocationName"), + } +} + +// String returns a human-readable description of this Quota Allocation ID +func (id QuotaAllocationId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Resource Provider Name: %q", id.ResourceProviderName), + fmt.Sprintf("Quota Allocation Name: %q", id.QuotaAllocationName), + } + return fmt.Sprintf("Quota Allocation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation_test.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation_test.go new file mode 100644 index 00000000000..523fb18bd33 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/id_quotaallocation_test.go @@ -0,0 +1,402 @@ +package subscriptionquotaallocation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &QuotaAllocationId{} + +func TestNewQuotaAllocationID(t *testing.T) { + id := NewQuotaAllocationID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "quotaAllocationName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.ResourceProviderName != "resourceProviderName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceProviderName'", id.ResourceProviderName, "resourceProviderName") + } + + if id.QuotaAllocationName != "quotaAllocationName" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaAllocationName'", id.QuotaAllocationName, "quotaAllocationName") + } +} + +func TestFormatQuotaAllocationID(t *testing.T) { + actual := NewQuotaAllocationID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "quotaAllocationName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations/quotaAllocationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQuotaAllocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaAllocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations/quotaAllocationName", + Expected: &QuotaAllocationId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + QuotaAllocationName: "quotaAllocationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations/quotaAllocationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaAllocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.QuotaAllocationName != v.Expected.QuotaAllocationName { + t.Fatalf("Expected %q but got %q for QuotaAllocationName", v.Expected.QuotaAllocationName, actual.QuotaAllocationName) + } + + } +} + +func TestParseQuotaAllocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaAllocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations/quotaAllocationName", + Expected: &QuotaAllocationId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + QuotaAllocationName: "quotaAllocationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocations/quotaAllocationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnS/qUoTaAlLoCaTiOnNaMe", + Expected: &QuotaAllocationId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "gRoUpQuOtAnAmE", + ResourceProviderName: "rEsOuRcEpRoViDeRnAmE", + QuotaAllocationName: "qUoTaAlLoCaTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnS/qUoTaAlLoCaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaAllocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.QuotaAllocationName != v.Expected.QuotaAllocationName { + t.Fatalf("Expected %q but got %q for QuotaAllocationName", v.Expected.QuotaAllocationName, actual.QuotaAllocationName) + } + + } +} + +func TestSegmentsForQuotaAllocationId(t *testing.T) { + segments := QuotaAllocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QuotaAllocationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationlist.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationlist.go new file mode 100644 index 00000000000..eaf112845c1 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationlist.go @@ -0,0 +1,53 @@ +package subscriptionquotaallocation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionAllocationListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionQuotaAllocationsList +} + +// GroupQuotaSubscriptionAllocationList ... +func (c SubscriptionQuotaAllocationClient) GroupQuotaSubscriptionAllocationList(ctx context.Context, id QuotaAllocationId) (result GroupQuotaSubscriptionAllocationListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SubscriptionQuotaAllocationsList + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationrequestupdate.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationrequestupdate.go new file mode 100644 index 00000000000..7711dc3e697 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/method_groupquotasubscriptionallocationrequestupdate.go @@ -0,0 +1,75 @@ +package subscriptionquotaallocation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionAllocationRequestUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionQuotaAllocationsList +} + +// GroupQuotaSubscriptionAllocationRequestUpdate ... +func (c SubscriptionQuotaAllocationClient) GroupQuotaSubscriptionAllocationRequestUpdate(ctx context.Context, id QuotaAllocationId, input SubscriptionQuotaAllocationsList) (result GroupQuotaSubscriptionAllocationRequestUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GroupQuotaSubscriptionAllocationRequestUpdateThenPoll performs GroupQuotaSubscriptionAllocationRequestUpdate then polls until it's completed +func (c SubscriptionQuotaAllocationClient) GroupQuotaSubscriptionAllocationRequestUpdateThenPoll(ctx context.Context, id QuotaAllocationId, input SubscriptionQuotaAllocationsList) error { + result, err := c.GroupQuotaSubscriptionAllocationRequestUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GroupQuotaSubscriptionAllocationRequestUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GroupQuotaSubscriptionAllocationRequestUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocations.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocations.go new file mode 100644 index 00000000000..fc4ad76aa2f --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocations.go @@ -0,0 +1,8 @@ +package subscriptionquotaallocation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaAllocations struct { + Properties *SubscriptionQuotaDetails `json:"properties,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslist.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslist.go new file mode 100644 index 00000000000..bbfb4df2d0c --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslist.go @@ -0,0 +1,16 @@ +package subscriptionquotaallocation + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaAllocationsList struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionQuotaAllocationsListProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslistproperties.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslistproperties.go new file mode 100644 index 00000000000..e39ca364f08 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotaallocationslistproperties.go @@ -0,0 +1,10 @@ +package subscriptionquotaallocation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaAllocationsListProperties struct { + NextLink *string `json:"nextLink,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + Value *[]SubscriptionQuotaAllocations `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetails.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetails.go new file mode 100644 index 00000000000..2cc364957c9 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetails.go @@ -0,0 +1,11 @@ +package subscriptionquotaallocation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaDetails struct { + Limit *int64 `json:"limit,omitempty"` + Name *SubscriptionQuotaDetailsName `json:"name,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ShareableQuota *int64 `json:"shareableQuota,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetailsname.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetailsname.go new file mode 100644 index 00000000000..0ba6329c856 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/model_subscriptionquotadetailsname.go @@ -0,0 +1,9 @@ +package subscriptionquotaallocation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaDetailsName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocation/version.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/version.go new file mode 100644 index 00000000000..cdd83f15e3f --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocation/version.go @@ -0,0 +1,10 @@ +package subscriptionquotaallocation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/subscriptionquotaallocation/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/README.md b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/README.md new file mode 100644 index 00000000000..407176eb8f0 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest` Documentation + +The `subscriptionquotaallocationrequest` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest" +``` + + +### Client Initialization + +```go +client := subscriptionquotaallocationrequest.NewSubscriptionQuotaAllocationRequestClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionQuotaAllocationRequestClient.GroupQuotaSubscriptionAllocationRequestGet` + +```go +ctx := context.TODO() +id := subscriptionquotaallocationrequest.NewQuotaAllocationRequestID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "allocationId") + +read, err := client.GroupQuotaSubscriptionAllocationRequestGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionQuotaAllocationRequestClient.GroupQuotaSubscriptionAllocationRequestList` + +```go +ctx := context.TODO() +id := subscriptionquotaallocationrequest.NewGroupQuotaResourceProviderID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName") + +// alternatively `client.GroupQuotaSubscriptionAllocationRequestList(ctx, id, subscriptionquotaallocationrequest.DefaultGroupQuotaSubscriptionAllocationRequestListOperationOptions())` can be used to do batched pagination +items, err := client.GroupQuotaSubscriptionAllocationRequestListComplete(ctx, id, subscriptionquotaallocationrequest.DefaultGroupQuotaSubscriptionAllocationRequestListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/client.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/client.go new file mode 100644 index 00000000000..abc9acce127 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/client.go @@ -0,0 +1,26 @@ +package subscriptionquotaallocationrequest + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionQuotaAllocationRequestClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionQuotaAllocationRequestClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionQuotaAllocationRequestClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "subscriptionquotaallocationrequest", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionQuotaAllocationRequestClient: %+v", err) + } + + return &SubscriptionQuotaAllocationRequestClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/constants.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/constants.go new file mode 100644 index 00000000000..44b2798697c --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/constants.go @@ -0,0 +1,66 @@ +package subscriptionquotaallocationrequest + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestState string + +const ( + RequestStateAccepted RequestState = "Accepted" + RequestStateCanceled RequestState = "Canceled" + RequestStateCreated RequestState = "Created" + RequestStateFailed RequestState = "Failed" + RequestStateInProgress RequestState = "InProgress" + RequestStateInvalid RequestState = "Invalid" + RequestStateSucceeded RequestState = "Succeeded" +) + +func PossibleValuesForRequestState() []string { + return []string{ + string(RequestStateAccepted), + string(RequestStateCanceled), + string(RequestStateCreated), + string(RequestStateFailed), + string(RequestStateInProgress), + string(RequestStateInvalid), + string(RequestStateSucceeded), + } +} + +func (s *RequestState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestState(input string) (*RequestState, error) { + vals := map[string]RequestState{ + "accepted": RequestStateAccepted, + "canceled": RequestStateCanceled, + "created": RequestStateCreated, + "failed": RequestStateFailed, + "inprogress": RequestStateInProgress, + "invalid": RequestStateInvalid, + "succeeded": RequestStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestState(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider.go new file mode 100644 index 00000000000..3835402c0e5 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider.go @@ -0,0 +1,141 @@ +package subscriptionquotaallocationrequest + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupQuotaResourceProviderId{}) +} + +var _ resourceids.ResourceId = &GroupQuotaResourceProviderId{} + +// GroupQuotaResourceProviderId is a struct representing the Resource ID for a Group Quota Resource Provider +type GroupQuotaResourceProviderId struct { + ManagementGroupId string + SubscriptionId string + GroupQuotaName string + ResourceProviderName string +} + +// NewGroupQuotaResourceProviderID returns a new GroupQuotaResourceProviderId struct +func NewGroupQuotaResourceProviderID(managementGroupId string, subscriptionId string, groupQuotaName string, resourceProviderName string) GroupQuotaResourceProviderId { + return GroupQuotaResourceProviderId{ + ManagementGroupId: managementGroupId, + SubscriptionId: subscriptionId, + GroupQuotaName: groupQuotaName, + ResourceProviderName: resourceProviderName, + } +} + +// ParseGroupQuotaResourceProviderID parses 'input' into a GroupQuotaResourceProviderId +func ParseGroupQuotaResourceProviderID(input string) (*GroupQuotaResourceProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaResourceProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaResourceProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupQuotaResourceProviderIDInsensitively parses 'input' case-insensitively into a GroupQuotaResourceProviderId +// note: this method should only be used for API response data and not user input +func ParseGroupQuotaResourceProviderIDInsensitively(input string) (*GroupQuotaResourceProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupQuotaResourceProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupQuotaResourceProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupQuotaResourceProviderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.ResourceProviderName, ok = input.Parsed["resourceProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceProviderName", input) + } + + return nil +} + +// ValidateGroupQuotaResourceProviderID checks that 'input' can be parsed as a Group Quota Resource Provider ID +func ValidateGroupQuotaResourceProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupQuotaResourceProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Quota Resource Provider ID +func (id GroupQuotaResourceProviderId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/subscriptions/%s/providers/Microsoft.Quota/groupQuotas/%s/resourceProviders/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.SubscriptionId, id.GroupQuotaName, id.ResourceProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Quota Resource Provider ID +func (id GroupQuotaResourceProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticResourceProviders", "resourceProviders", "resourceProviders"), + resourceids.UserSpecifiedSegment("resourceProviderName", "resourceProviderName"), + } +} + +// String returns a human-readable description of this Group Quota Resource Provider ID +func (id GroupQuotaResourceProviderId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Resource Provider Name: %q", id.ResourceProviderName), + } + return fmt.Sprintf("Group Quota Resource Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider_test.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider_test.go new file mode 100644 index 00000000000..3a17e7553dc --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_groupquotaresourceprovider_test.go @@ -0,0 +1,357 @@ +package subscriptionquotaallocationrequest + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupQuotaResourceProviderId{} + +func TestNewGroupQuotaResourceProviderID(t *testing.T) { + id := NewGroupQuotaResourceProviderID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.ResourceProviderName != "resourceProviderName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceProviderName'", id.ResourceProviderName, "resourceProviderName") + } +} + +func TestFormatGroupQuotaResourceProviderID(t *testing.T) { + actual := NewGroupQuotaResourceProviderID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupQuotaResourceProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaResourceProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Expected: &GroupQuotaResourceProviderId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaResourceProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + } +} + +func TestParseGroupQuotaResourceProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupQuotaResourceProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Expected: &GroupQuotaResourceProviderId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE", + Expected: &GroupQuotaResourceProviderId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "gRoUpQuOtAnAmE", + ResourceProviderName: "rEsOuRcEpRoViDeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupQuotaResourceProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + } +} + +func TestSegmentsForGroupQuotaResourceProviderId(t *testing.T) { + segments := GroupQuotaResourceProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupQuotaResourceProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest.go new file mode 100644 index 00000000000..c1d9097ab7b --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest.go @@ -0,0 +1,150 @@ +package subscriptionquotaallocationrequest + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QuotaAllocationRequestId{}) +} + +var _ resourceids.ResourceId = &QuotaAllocationRequestId{} + +// QuotaAllocationRequestId is a struct representing the Resource ID for a Quota Allocation Request +type QuotaAllocationRequestId struct { + ManagementGroupId string + SubscriptionId string + GroupQuotaName string + ResourceProviderName string + AllocationId string +} + +// NewQuotaAllocationRequestID returns a new QuotaAllocationRequestId struct +func NewQuotaAllocationRequestID(managementGroupId string, subscriptionId string, groupQuotaName string, resourceProviderName string, allocationId string) QuotaAllocationRequestId { + return QuotaAllocationRequestId{ + ManagementGroupId: managementGroupId, + SubscriptionId: subscriptionId, + GroupQuotaName: groupQuotaName, + ResourceProviderName: resourceProviderName, + AllocationId: allocationId, + } +} + +// ParseQuotaAllocationRequestID parses 'input' into a QuotaAllocationRequestId +func ParseQuotaAllocationRequestID(input string) (*QuotaAllocationRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaAllocationRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaAllocationRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQuotaAllocationRequestIDInsensitively parses 'input' case-insensitively into a QuotaAllocationRequestId +// note: this method should only be used for API response data and not user input +func ParseQuotaAllocationRequestIDInsensitively(input string) (*QuotaAllocationRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaAllocationRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaAllocationRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QuotaAllocationRequestId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ManagementGroupId, ok = input.Parsed["managementGroupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managementGroupId", input) + } + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.GroupQuotaName, ok = input.Parsed["groupQuotaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupQuotaName", input) + } + + if id.ResourceProviderName, ok = input.Parsed["resourceProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceProviderName", input) + } + + if id.AllocationId, ok = input.Parsed["allocationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "allocationId", input) + } + + return nil +} + +// ValidateQuotaAllocationRequestID checks that 'input' can be parsed as a Quota Allocation Request ID +func ValidateQuotaAllocationRequestID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseQuotaAllocationRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Quota Allocation Request ID +func (id QuotaAllocationRequestId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/subscriptions/%s/providers/Microsoft.Quota/groupQuotas/%s/resourceProviders/%s/quotaAllocationRequests/%s" + return fmt.Sprintf(fmtString, id.ManagementGroupId, id.SubscriptionId, id.GroupQuotaName, id.ResourceProviderName, id.AllocationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Quota Allocation Request ID +func (id QuotaAllocationRequestId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("managementGroupId", "managementGroupId"), + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticGroupQuotas", "groupQuotas", "groupQuotas"), + resourceids.UserSpecifiedSegment("groupQuotaName", "groupQuotaName"), + resourceids.StaticSegment("staticResourceProviders", "resourceProviders", "resourceProviders"), + resourceids.UserSpecifiedSegment("resourceProviderName", "resourceProviderName"), + resourceids.StaticSegment("staticQuotaAllocationRequests", "quotaAllocationRequests", "quotaAllocationRequests"), + resourceids.UserSpecifiedSegment("allocationId", "allocationId"), + } +} + +// String returns a human-readable description of this Quota Allocation Request ID +func (id QuotaAllocationRequestId) String() string { + components := []string{ + fmt.Sprintf("Management Group: %q", id.ManagementGroupId), + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Group Quota Name: %q", id.GroupQuotaName), + fmt.Sprintf("Resource Provider Name: %q", id.ResourceProviderName), + fmt.Sprintf("Allocation: %q", id.AllocationId), + } + return fmt.Sprintf("Quota Allocation Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest_test.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest_test.go new file mode 100644 index 00000000000..3fc8806200c --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/id_quotaallocationrequest_test.go @@ -0,0 +1,402 @@ +package subscriptionquotaallocationrequest + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &QuotaAllocationRequestId{} + +func TestNewQuotaAllocationRequestID(t *testing.T) { + id := NewQuotaAllocationRequestID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "allocationId") + + if id.ManagementGroupId != "managementGroupId" { + t.Fatalf("Expected %q but got %q for Segment 'ManagementGroupId'", id.ManagementGroupId, "managementGroupId") + } + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.GroupQuotaName != "groupQuotaName" { + t.Fatalf("Expected %q but got %q for Segment 'GroupQuotaName'", id.GroupQuotaName, "groupQuotaName") + } + + if id.ResourceProviderName != "resourceProviderName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceProviderName'", id.ResourceProviderName, "resourceProviderName") + } + + if id.AllocationId != "allocationId" { + t.Fatalf("Expected %q but got %q for Segment 'AllocationId'", id.AllocationId, "allocationId") + } +} + +func TestFormatQuotaAllocationRequestID(t *testing.T) { + actual := NewQuotaAllocationRequestID("managementGroupId", "12345678-1234-9876-4563-123456789012", "groupQuotaName", "resourceProviderName", "allocationId").ID() + expected := "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests/allocationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQuotaAllocationRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaAllocationRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests/allocationId", + Expected: &QuotaAllocationRequestId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + AllocationId: "allocationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests/allocationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaAllocationRequestID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.AllocationId != v.Expected.AllocationId { + t.Fatalf("Expected %q but got %q for AllocationId", v.Expected.AllocationId, actual.AllocationId) + } + + } +} + +func TestParseQuotaAllocationRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaAllocationRequestId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests/allocationId", + Expected: &QuotaAllocationRequestId{ + ManagementGroupId: "managementGroupId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "groupQuotaName", + ResourceProviderName: "resourceProviderName", + AllocationId: "allocationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/managementGroupId/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Quota/groupQuotas/groupQuotaName/resourceProviders/resourceProviderName/quotaAllocationRequests/allocationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnReQuEsTs/aLlOcAtIoNiD", + Expected: &QuotaAllocationRequestId{ + ManagementGroupId: "mAnAgEmEnTgRoUpId", + SubscriptionId: "12345678-1234-9876-4563-123456789012", + GroupQuotaName: "gRoUpQuOtAnAmE", + ResourceProviderName: "rEsOuRcEpRoViDeRnAmE", + AllocationId: "aLlOcAtIoNiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/mAnAgEmEnTgRoUpId/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.qUoTa/gRoUpQuOtAs/gRoUpQuOtAnAmE/rEsOuRcEpRoViDeRs/rEsOuRcEpRoViDeRnAmE/qUoTaAlLoCaTiOnReQuEsTs/aLlOcAtIoNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaAllocationRequestIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ManagementGroupId != v.Expected.ManagementGroupId { + t.Fatalf("Expected %q but got %q for ManagementGroupId", v.Expected.ManagementGroupId, actual.ManagementGroupId) + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.GroupQuotaName != v.Expected.GroupQuotaName { + t.Fatalf("Expected %q but got %q for GroupQuotaName", v.Expected.GroupQuotaName, actual.GroupQuotaName) + } + + if actual.ResourceProviderName != v.Expected.ResourceProviderName { + t.Fatalf("Expected %q but got %q for ResourceProviderName", v.Expected.ResourceProviderName, actual.ResourceProviderName) + } + + if actual.AllocationId != v.Expected.AllocationId { + t.Fatalf("Expected %q but got %q for AllocationId", v.Expected.AllocationId, actual.AllocationId) + } + + } +} + +func TestSegmentsForQuotaAllocationRequestId(t *testing.T) { + segments := QuotaAllocationRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QuotaAllocationRequestId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestget.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestget.go new file mode 100644 index 00000000000..866e5fc993b --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestget.go @@ -0,0 +1,53 @@ +package subscriptionquotaallocationrequest + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionAllocationRequestGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *QuotaAllocationRequestStatus +} + +// GroupQuotaSubscriptionAllocationRequestGet ... +func (c SubscriptionQuotaAllocationRequestClient) GroupQuotaSubscriptionAllocationRequestGet(ctx context.Context, id QuotaAllocationRequestId) (result GroupQuotaSubscriptionAllocationRequestGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model QuotaAllocationRequestStatus + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestlist.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestlist.go new file mode 100644 index 00000000000..c6a0b124b4b --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/method_groupquotasubscriptionallocationrequestlist.go @@ -0,0 +1,134 @@ +package subscriptionquotaallocationrequest + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupQuotaSubscriptionAllocationRequestListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]QuotaAllocationRequestStatus +} + +type GroupQuotaSubscriptionAllocationRequestListCompleteResult struct { + LatestHttpResponse *http.Response + Items []QuotaAllocationRequestStatus +} + +type GroupQuotaSubscriptionAllocationRequestListOperationOptions struct { + Filter *string +} + +func DefaultGroupQuotaSubscriptionAllocationRequestListOperationOptions() GroupQuotaSubscriptionAllocationRequestListOperationOptions { + return GroupQuotaSubscriptionAllocationRequestListOperationOptions{} +} + +func (o GroupQuotaSubscriptionAllocationRequestListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GroupQuotaSubscriptionAllocationRequestListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GroupQuotaSubscriptionAllocationRequestListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type GroupQuotaSubscriptionAllocationRequestListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GroupQuotaSubscriptionAllocationRequestListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GroupQuotaSubscriptionAllocationRequestList ... +func (c SubscriptionQuotaAllocationRequestClient) GroupQuotaSubscriptionAllocationRequestList(ctx context.Context, id GroupQuotaResourceProviderId, options GroupQuotaSubscriptionAllocationRequestListOperationOptions) (result GroupQuotaSubscriptionAllocationRequestListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &GroupQuotaSubscriptionAllocationRequestListCustomPager{}, + Path: fmt.Sprintf("%s/quotaAllocationRequests", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]QuotaAllocationRequestStatus `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GroupQuotaSubscriptionAllocationRequestListComplete retrieves all the results into a single object +func (c SubscriptionQuotaAllocationRequestClient) GroupQuotaSubscriptionAllocationRequestListComplete(ctx context.Context, id GroupQuotaResourceProviderId, options GroupQuotaSubscriptionAllocationRequestListOperationOptions) (GroupQuotaSubscriptionAllocationRequestListCompleteResult, error) { + return c.GroupQuotaSubscriptionAllocationRequestListCompleteMatchingPredicate(ctx, id, options, QuotaAllocationRequestStatusOperationPredicate{}) +} + +// GroupQuotaSubscriptionAllocationRequestListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionQuotaAllocationRequestClient) GroupQuotaSubscriptionAllocationRequestListCompleteMatchingPredicate(ctx context.Context, id GroupQuotaResourceProviderId, options GroupQuotaSubscriptionAllocationRequestListOperationOptions, predicate QuotaAllocationRequestStatusOperationPredicate) (result GroupQuotaSubscriptionAllocationRequestListCompleteResult, err error) { + items := make([]QuotaAllocationRequestStatus, 0) + + resp, err := c.GroupQuotaSubscriptionAllocationRequestList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GroupQuotaSubscriptionAllocationRequestListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbase.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbase.go new file mode 100644 index 00000000000..97500914b98 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbase.go @@ -0,0 +1,8 @@ +package subscriptionquotaallocationrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestBase struct { + Properties *QuotaAllocationRequestBaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbaseproperties.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbaseproperties.go new file mode 100644 index 00000000000..9b90e27be27 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbaseproperties.go @@ -0,0 +1,10 @@ +package subscriptionquotaallocationrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestBaseProperties struct { + Limit *int64 `json:"limit,omitempty"` + Name *QuotaAllocationRequestBasePropertiesName `json:"name,omitempty"` + Region *string `json:"region,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbasepropertiesname.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbasepropertiesname.go new file mode 100644 index 00000000000..d28f117a5a7 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequestbasepropertiesname.go @@ -0,0 +1,9 @@ +package subscriptionquotaallocationrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestBasePropertiesName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatus.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatus.go new file mode 100644 index 00000000000..7ebcf8b115e --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatus.go @@ -0,0 +1,16 @@ +package subscriptionquotaallocationrequest + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestStatus struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QuotaAllocationRequestStatusProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatusproperties.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatusproperties.go new file mode 100644 index 00000000000..f03686f3f37 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/model_quotaallocationrequeststatusproperties.go @@ -0,0 +1,29 @@ +package subscriptionquotaallocationrequest + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestStatusProperties struct { + FaultCode *string `json:"faultCode,omitempty"` + ProvisioningState *RequestState `json:"provisioningState,omitempty"` + RequestSubmitTime *string `json:"requestSubmitTime,omitempty"` + RequestedResource *QuotaAllocationRequestBase `json:"requestedResource,omitempty"` +} + +func (o *QuotaAllocationRequestStatusProperties) GetRequestSubmitTimeAsTime() (*time.Time, error) { + if o.RequestSubmitTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RequestSubmitTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaAllocationRequestStatusProperties) SetRequestSubmitTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RequestSubmitTime = &formatted +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/predicates.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/predicates.go new file mode 100644 index 00000000000..df0912f3621 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/predicates.go @@ -0,0 +1,27 @@ +package subscriptionquotaallocationrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaAllocationRequestStatusOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p QuotaAllocationRequestStatusOperationPredicate) Matches(input QuotaAllocationRequestStatus) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/version.go b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/version.go new file mode 100644 index 00000000000..cb05ff595f1 --- /dev/null +++ b/resource-manager/quota/2025-03-01/subscriptionquotaallocationrequest/version.go @@ -0,0 +1,10 @@ +package subscriptionquotaallocationrequest + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/subscriptionquotaallocationrequest/2025-03-01" +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/README.md b/resource-manager/quota/2025-03-01/usagesinformation/README.md new file mode 100644 index 00000000000..c990ebc2854 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/usagesinformation` Documentation + +The `usagesinformation` SDK allows for interaction with Azure Resource Manager `quota` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/quota/2025-03-01/usagesinformation" +``` + + +### Client Initialization + +```go +client := usagesinformation.NewUsagesInformationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsagesInformationClient.UsagesGet` + +```go +ctx := context.TODO() +id := usagesinformation.NewScopedUsageID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "usageName") + +read, err := client.UsagesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `UsagesInformationClient.UsagesList` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.UsagesList(ctx, id)` can be used to do batched pagination +items, err := client.UsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/quota/2025-03-01/usagesinformation/client.go b/resource-manager/quota/2025-03-01/usagesinformation/client.go new file mode 100644 index 00000000000..1eadace30e6 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/client.go @@ -0,0 +1,26 @@ +package usagesinformation + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesInformationClient struct { + Client *resourcemanager.Client +} + +func NewUsagesInformationClientWithBaseURI(sdkApi sdkEnv.Api) (*UsagesInformationClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "usagesinformation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsagesInformationClient: %+v", err) + } + + return &UsagesInformationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/constants.go b/resource-manager/quota/2025-03-01/usagesinformation/constants.go new file mode 100644 index 00000000000..171bd8244c4 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/constants.go @@ -0,0 +1,51 @@ +package usagesinformation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesTypes string + +const ( + UsagesTypesCombined UsagesTypes = "Combined" + UsagesTypesIndividual UsagesTypes = "Individual" +) + +func PossibleValuesForUsagesTypes() []string { + return []string{ + string(UsagesTypesCombined), + string(UsagesTypesIndividual), + } +} + +func (s *UsagesTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsagesTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsagesTypes(input string) (*UsagesTypes, error) { + vals := map[string]UsagesTypes{ + "combined": UsagesTypesCombined, + "individual": UsagesTypesIndividual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsagesTypes(input) + return &out, nil +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage.go b/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage.go new file mode 100644 index 00000000000..6e492a72630 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage.go @@ -0,0 +1,120 @@ +package usagesinformation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedUsageId{}) +} + +var _ resourceids.ResourceId = &ScopedUsageId{} + +// ScopedUsageId is a struct representing the Resource ID for a Scoped Usage +type ScopedUsageId struct { + Scope string + UsageName string +} + +// NewScopedUsageID returns a new ScopedUsageId struct +func NewScopedUsageID(scope string, usageName string) ScopedUsageId { + return ScopedUsageId{ + Scope: scope, + UsageName: usageName, + } +} + +// ParseScopedUsageID parses 'input' into a ScopedUsageId +func ParseScopedUsageID(input string) (*ScopedUsageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedUsageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedUsageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedUsageIDInsensitively parses 'input' case-insensitively into a ScopedUsageId +// note: this method should only be used for API response data and not user input +func ParseScopedUsageIDInsensitively(input string) (*ScopedUsageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedUsageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedUsageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedUsageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.UsageName, ok = input.Parsed["usageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "usageName", input) + } + + return nil +} + +// ValidateScopedUsageID checks that 'input' can be parsed as a Scoped Usage ID +func ValidateScopedUsageID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedUsageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Usage ID +func (id ScopedUsageId) ID() string { + fmtString := "/%s/providers/Microsoft.Quota/usages/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.UsageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Usage ID +func (id ScopedUsageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftQuota", "Microsoft.Quota", "Microsoft.Quota"), + resourceids.StaticSegment("staticUsages", "usages", "usages"), + resourceids.UserSpecifiedSegment("usageName", "usageName"), + } +} + +// String returns a human-readable description of this Scoped Usage ID +func (id ScopedUsageId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Usage Name: %q", id.UsageName), + } + return fmt.Sprintf("Scoped Usage (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage_test.go b/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage_test.go new file mode 100644 index 00000000000..2eaaec7bb2a --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/id_scopedusage_test.go @@ -0,0 +1,222 @@ +package usagesinformation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedUsageId{} + +func TestNewScopedUsageID(t *testing.T) { + id := NewScopedUsageID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "usageName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.UsageName != "usageName" { + t.Fatalf("Expected %q but got %q for Segment 'UsageName'", id.UsageName, "usageName") + } +} + +func TestFormatScopedUsageID(t *testing.T) { + actual := NewScopedUsageID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "usageName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages/usageName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedUsageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedUsageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages/usageName", + Expected: &ScopedUsageId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + UsageName: "usageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages/usageName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedUsageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.UsageName != v.Expected.UsageName { + t.Fatalf("Expected %q but got %q for UsageName", v.Expected.UsageName, actual.UsageName) + } + + } +} + +func TestParseScopedUsageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedUsageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/uSaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages/usageName", + Expected: &ScopedUsageId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + UsageName: "usageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Quota/usages/usageName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/uSaGeS/uSaGeNaMe", + Expected: &ScopedUsageId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + UsageName: "uSaGeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.qUoTa/uSaGeS/uSaGeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedUsageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.UsageName != v.Expected.UsageName { + t.Fatalf("Expected %q but got %q for UsageName", v.Expected.UsageName, actual.UsageName) + } + + } +} + +func TestSegmentsForScopedUsageId(t *testing.T) { + segments := ScopedUsageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedUsageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/method_usagesget.go b/resource-manager/quota/2025-03-01/usagesinformation/method_usagesget.go new file mode 100644 index 00000000000..bba4502ecb6 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/method_usagesget.go @@ -0,0 +1,53 @@ +package usagesinformation + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CurrentUsagesBase +} + +// UsagesGet ... +func (c UsagesInformationClient) UsagesGet(ctx context.Context, id ScopedUsageId) (result UsagesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CurrentUsagesBase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/method_usageslist.go b/resource-manager/quota/2025-03-01/usagesinformation/method_usageslist.go new file mode 100644 index 00000000000..380d147012d --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/method_usageslist.go @@ -0,0 +1,106 @@ +package usagesinformation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CurrentUsagesBase +} + +type UsagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CurrentUsagesBase +} + +type UsagesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *UsagesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// UsagesList ... +func (c UsagesInformationClient) UsagesList(ctx context.Context, id commonids.ScopeId) (result UsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &UsagesListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Quota/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CurrentUsagesBase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UsagesListComplete retrieves all the results into a single object +func (c UsagesInformationClient) UsagesListComplete(ctx context.Context, id commonids.ScopeId) (UsagesListCompleteResult, error) { + return c.UsagesListCompleteMatchingPredicate(ctx, id, CurrentUsagesBaseOperationPredicate{}) +} + +// UsagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesInformationClient) UsagesListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate CurrentUsagesBaseOperationPredicate) (result UsagesListCompleteResult, err error) { + items := make([]CurrentUsagesBase, 0) + + resp, err := c.UsagesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = UsagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/model_currentusagesbase.go b/resource-manager/quota/2025-03-01/usagesinformation/model_currentusagesbase.go new file mode 100644 index 00000000000..8c388b2b223 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/model_currentusagesbase.go @@ -0,0 +1,11 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentUsagesBase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UsagesProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/model_resourcename.go b/resource-manager/quota/2025-03-01/usagesinformation/model_resourcename.go new file mode 100644 index 00000000000..99e25187911 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/model_resourcename.go @@ -0,0 +1,9 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/model_usagesobject.go b/resource-manager/quota/2025-03-01/usagesinformation/model_usagesobject.go new file mode 100644 index 00000000000..b7cf883cb1a --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/model_usagesobject.go @@ -0,0 +1,9 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesObject struct { + UsagesType *UsagesTypes `json:"usagesType,omitempty"` + Value int64 `json:"value"` +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/model_usagesproperties.go b/resource-manager/quota/2025-03-01/usagesinformation/model_usagesproperties.go new file mode 100644 index 00000000000..1492ede8bc2 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/model_usagesproperties.go @@ -0,0 +1,14 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesProperties struct { + IsQuotaApplicable *bool `json:"isQuotaApplicable,omitempty"` + Name *ResourceName `json:"name,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *string `json:"unit,omitempty"` + Usages *UsagesObject `json:"usages,omitempty"` +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/predicates.go b/resource-manager/quota/2025-03-01/usagesinformation/predicates.go new file mode 100644 index 00000000000..994b730de5f --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/predicates.go @@ -0,0 +1,27 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentUsagesBaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CurrentUsagesBaseOperationPredicate) Matches(input CurrentUsagesBase) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/quota/2025-03-01/usagesinformation/version.go b/resource-manager/quota/2025-03-01/usagesinformation/version.go new file mode 100644 index 00000000000..9b1a3219a21 --- /dev/null +++ b/resource-manager/quota/2025-03-01/usagesinformation/version.go @@ -0,0 +1,10 @@ +package usagesinformation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/usagesinformation/2025-03-01" +}