From ab65d6c91a01959e2c3f94d83162c4c9fff40246 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Tue, 12 Mar 2024 15:06:07 +0000 Subject: [PATCH] Updating based on ffd187e3 --- .../2023-08-01-preview/arcsettings/README.md | 163 ++++++ .../2023-08-01-preview/arcsettings/client.go | 26 + .../arcsettings/constants.go | 277 ++++++++++ .../arcsettings/id_arcsetting.go | 134 +++++ .../arcsettings/id_arcsetting_test.go | 327 +++++++++++ .../arcsettings/id_cluster.go | 125 +++++ .../arcsettings/id_cluster_test.go | 282 ++++++++++ .../arcsettings/method_arcsettingscreate.go | 58 ++ .../arcsettings/method_arcsettingsdelete.go | 71 +++ .../arcsettings/method_arcsettingsget.go | 54 ++ .../method_arcsettingslistbycluster.go | 91 ++++ .../arcsettings/method_arcsettingsupdate.go | 58 ++ ...thod_consentandinstalldefaultextensions.go | 55 ++ .../arcsettings/method_createidentity.go | 71 +++ .../arcsettings/method_generatepassword.go | 55 ++ .../method_initializedisableprocess.go | 70 +++ .../arcsettings/model_arcidentityresponse.go | 8 + .../model_arcidentityresponseproperties.go | 11 + .../arcsettings/model_arcsetting.go | 16 + .../arcsettings/model_arcsettingproperties.go | 17 + .../arcsettings/model_arcsettingspatch.go | 9 + .../model_arcsettingspatchproperties.go | 8 + .../model_defaultextensiondetails.go | 27 + .../arcsettings/model_passwordcredential.go | 41 ++ .../arcsettings/model_pernodestate.go | 11 + .../arcsettings/predicates.go | 27 + .../2023-08-01-preview/arcsettings/version.go | 12 + .../2023-08-01-preview/client.go | 127 +++++ .../2023-08-01-preview/cluster/README.md | 66 +++ .../2023-08-01-preview/cluster/client.go | 26 + .../2023-08-01-preview/cluster/constants.go | 510 ++++++++++++++++++ .../2023-08-01-preview/cluster/id_cluster.go | 125 +++++ .../cluster/id_cluster_test.go | 282 ++++++++++ .../cluster/method_createidentity.go | 71 +++ .../method_extendsoftwareassurancebenefit.go | 75 +++ .../cluster/method_uploadcertificate.go | 73 +++ .../cluster/model_cluster.go | 20 + .../cluster/model_clusterdesiredproperties.go | 9 + .../cluster/model_clusteridentityresponse.go | 8 + ...model_clusteridentityresponseproperties.go | 11 + .../cluster/model_clusternode.go | 40 ++ .../cluster/model_clusterproperties.go | 69 +++ .../model_clusterreportedproperties.go | 36 ++ ...odel_isolatedvmattestationconfiguration.go | 10 + .../cluster/model_rawcertificatedata.go | 8 + .../model_softwareassurancechangerequest.go | 8 + ...oftwareassurancechangerequestproperties.go | 8 + .../model_softwareassuranceproperties.go | 28 + .../cluster/model_uploadcertificaterequest.go | 8 + .../2023-08-01-preview/cluster/version.go | 12 + .../2023-08-01-preview/clusters/README.md | 125 +++++ .../2023-08-01-preview/clusters/client.go | 26 + .../2023-08-01-preview/clusters/constants.go | 510 ++++++++++++++++++ .../2023-08-01-preview/clusters/id_cluster.go | 125 +++++ .../clusters/id_cluster_test.go | 282 ++++++++++ .../clusters/method_create.go | 58 ++ .../clusters/method_delete.go | 71 +++ .../2023-08-01-preview/clusters/method_get.go | 54 ++ .../clusters/method_listbyresourcegroup.go | 92 ++++ .../clusters/method_listbysubscription.go | 92 ++++ .../clusters/method_update.go | 58 ++ .../clusters/model_cluster.go | 20 + .../model_clusterdesiredproperties.go | 9 + .../clusters/model_clusternode.go | 40 ++ .../clusters/model_clusterpatch.go | 14 + .../clusters/model_clusterpatchproperties.go | 11 + .../clusters/model_clusterproperties.go | 69 +++ .../model_clusterreportedproperties.go | 36 ++ ...odel_isolatedvmattestationconfiguration.go | 10 + .../model_softwareassuranceproperties.go | 28 + .../2023-08-01-preview/clusters/predicates.go | 32 ++ .../2023-08-01-preview/clusters/version.go | 12 + .../deploymentsettings/README.md | 82 +++ .../deploymentsettings/client.go | 26 + .../deploymentsettings/constants.go | 110 ++++ .../deploymentsettings/id_cluster.go | 125 +++++ .../deploymentsettings/id_cluster_test.go | 282 ++++++++++ .../id_deploymentsetting.go | 134 +++++ .../id_deploymentsetting_test.go | 327 +++++++++++ .../method_createorupdate.go | 75 +++ .../deploymentsettings/method_delete.go | 70 +++ .../deploymentsettings/method_get.go | 54 ++ .../method_listbyclusters.go | 91 ++++ .../model_adapterpropertyoverrides.go | 10 + .../deploymentsettings/model_cluster.go | 12 + .../model_deploymentconfiguration.go | 9 + .../model_deploymentdata.go | 19 + .../model_deploymentsetting.go | 16 + .../model_deploymentsettingsproperties.go | 12 + .../model_deploymentstatus.go | 9 + .../deploymentsettings/model_hostnetwork.go | 11 + .../model_infrastructurenetwork.go | 12 + .../deploymentsettings/model_intents.go | 16 + .../deploymentsettings/model_ippools.go | 9 + .../deploymentsettings/model_observability.go | 10 + .../model_optionalservices.go | 8 + .../deploymentsettings/model_physicalnodes.go | 9 + .../model_qospolicyoverrides.go | 10 + .../model_reportedproperties.go | 9 + .../deploymentsettings/model_scaleunits.go | 8 + .../model_securitysettings.go | 17 + .../deploymentsettings/model_step.go | 15 + .../deploymentsettings/model_storage.go | 8 + .../model_storagenetworks.go | 10 + .../model_validationstatus.go | 9 + ...del_virtualswitchconfigurationoverrides.go | 9 + .../deploymentsettings/predicates.go | 27 + .../deploymentsettings/version.go | 12 + .../2023-08-01-preview/edgedevices/README.md | 100 ++++ .../2023-08-01-preview/edgedevices/client.go | 26 + .../edgedevices/constants.go | 69 +++ .../edgedevices/id_scopededgedevice.go | 115 ++++ .../edgedevices/id_scopededgedevice_test.go | 222 ++++++++ .../edgedevices/method_createorupdate.go | 75 +++ .../edgedevices/method_delete.go | 71 +++ .../edgedevices/method_get.go | 54 ++ .../edgedevices/method_list.go | 92 ++++ .../edgedevices/method_validate.go | 75 +++ .../edgedevices/model_deviceconfiguration.go | 9 + .../edgedevices/model_edgedevice.go | 16 + .../edgedevices/model_edgedeviceproperties.go | 9 + .../edgedevices/model_nicdetail.go | 16 + .../edgedevices/model_validaterequest.go | 9 + .../edgedevices/model_validateresponse.go | 8 + .../edgedevices/predicates.go | 27 + .../2023-08-01-preview/edgedevices/version.go | 12 + .../2023-08-01-preview/extensions/README.md | 116 ++++ .../2023-08-01-preview/extensions/client.go | 26 + .../extensions/constants.go | 356 ++++++++++++ .../extensions/id_arcsetting.go | 134 +++++ .../extensions/id_arcsetting_test.go | 327 +++++++++++ .../extensions/id_extension.go | 143 +++++ .../extensions/id_extension_test.go | 372 +++++++++++++ .../extensions/method_create.go | 75 +++ .../extensions/method_delete.go | 71 +++ .../extensions/method_get.go | 54 ++ .../extensions/method_listbyarcsetting.go | 91 ++++ .../extensions/method_update.go | 75 +++ .../extensions/method_upgrade.go | 73 +++ .../extensions/model_extension.go | 16 + .../extensions/model_extensioninstanceview.go | 11 + .../model_extensioninstanceviewstatus.go | 30 ++ .../extensions/model_extensionparameters.go | 15 + .../extensions/model_extensionpatch.go | 8 + .../model_extensionpatchparameters.go | 11 + .../model_extensionpatchproperties.go | 8 + .../extensions/model_extensionproperties.go | 12 + .../model_extensionupgradeparameters.go | 8 + .../extensions/model_pernodeextensionstate.go | 12 + .../extensions/predicates.go | 27 + .../2023-08-01-preview/extensions/version.go | 12 + .../2023-08-01-preview/offers/README.md | 70 +++ .../2023-08-01-preview/offers/client.go | 26 + .../2023-08-01-preview/offers/id_cluster.go | 125 +++++ .../offers/id_cluster_test.go | 282 ++++++++++ .../2023-08-01-preview/offers/id_offer.go | 143 +++++ .../offers/id_offer_test.go | 372 +++++++++++++ .../2023-08-01-preview/offers/id_publisher.go | 134 +++++ .../offers/id_publisher_test.go | 327 +++++++++++ .../2023-08-01-preview/offers/method_get.go | 83 +++ .../offers/method_listbycluster.go | 119 ++++ .../offers/method_listbypublisher.go | 119 ++++ .../2023-08-01-preview/offers/model_offer.go | 16 + .../offers/model_offerproperties.go | 12 + .../offers/model_skumappings.go | 10 + .../2023-08-01-preview/offers/predicates.go | 27 + .../2023-08-01-preview/offers/version.go | 12 + .../2023-08-01-preview/publishers/README.md | 53 ++ .../2023-08-01-preview/publishers/client.go | 26 + .../publishers/id_cluster.go | 125 +++++ .../publishers/id_cluster_test.go | 282 ++++++++++ .../publishers/id_publisher.go | 134 +++++ .../publishers/id_publisher_test.go | 327 +++++++++++ .../publishers/method_get.go | 54 ++ .../publishers/method_listbycluster.go | 91 ++++ .../publishers/model_publisher.go | 16 + .../publishers/model_publisherproperties.go | 8 + .../publishers/predicates.go | 27 + .../2023-08-01-preview/publishers/version.go | 12 + .../2023-08-01-preview/skuses/README.md | 53 ++ .../2023-08-01-preview/skuses/client.go | 26 + .../2023-08-01-preview/skuses/id_offer.go | 143 +++++ .../skuses/id_offer_test.go | 372 +++++++++++++ .../2023-08-01-preview/skuses/id_sku.go | 152 ++++++ .../2023-08-01-preview/skuses/id_sku_test.go | 417 ++++++++++++++ .../skuses/method_skusget.go | 83 +++ .../skuses/method_skuslistbyoffer.go | 119 ++++ .../2023-08-01-preview/skuses/model_sku.go | 16 + .../skuses/model_skumappings.go | 10 + .../skuses/model_skuproperties.go | 13 + .../2023-08-01-preview/skuses/predicates.go | 27 + .../2023-08-01-preview/skuses/version.go | 12 + .../2023-08-01-preview/updateruns/README.md | 86 +++ .../2023-08-01-preview/updateruns/client.go | 26 + .../updateruns/constants.go | 107 ++++ .../updateruns/id_update.go | 134 +++++ .../updateruns/id_update_test.go | 327 +++++++++++ .../updateruns/id_updaterun.go | 143 +++++ .../updateruns/id_updaterun_test.go | 372 +++++++++++++ .../updateruns/method_delete.go | 71 +++ .../updateruns/method_get.go | 54 ++ .../updateruns/method_list.go | 91 ++++ .../updateruns/method_put.go | 58 ++ .../updateruns/model_step.go | 57 ++ .../updateruns/model_updaterun.go | 17 + .../updateruns/model_updaterunproperties.go | 43 ++ .../updateruns/predicates.go | 32 ++ .../2023-08-01-preview/updateruns/version.go | 12 + .../2023-08-01-preview/updates/README.md | 98 ++++ .../2023-08-01-preview/updates/client.go | 26 + .../2023-08-01-preview/updates/constants.go | 381 +++++++++++++ .../2023-08-01-preview/updates/id_cluster.go | 125 +++++ .../updates/id_cluster_test.go | 282 ++++++++++ .../2023-08-01-preview/updates/id_update.go | 134 +++++ .../updates/id_update_test.go | 327 +++++++++++ .../updates/method_delete.go | 71 +++ .../2023-08-01-preview/updates/method_get.go | 54 ++ .../2023-08-01-preview/updates/method_list.go | 91 ++++ .../2023-08-01-preview/updates/method_post.go | 70 +++ .../2023-08-01-preview/updates/method_put.go | 58 ++ .../updates/model_packageversioninfo.go | 28 + .../updates/model_precheckresult.go | 37 ++ .../updates/model_precheckresulttags.go | 9 + .../updates/model_update.go | 17 + .../updates/model_updateprerequisite.go | 10 + .../updates/model_updateproperties.go | 57 ++ .../updates/model_updatestateproperties.go | 9 + .../2023-08-01-preview/updates/predicates.go | 32 ++ .../2023-08-01-preview/updates/version.go | 12 + .../updatesummaries/README.md | 86 +++ .../updatesummaries/client.go | 26 + .../updatesummaries/constants.go | 263 +++++++++ .../updatesummaries/id_cluster.go | 125 +++++ .../updatesummaries/id_cluster_test.go | 282 ++++++++++ .../updatesummaries/method_delete.go | 71 +++ .../updatesummaries/method_get.go | 55 ++ .../updatesummaries/method_list.go | 91 ++++ .../updatesummaries/method_put.go | 59 ++ .../model_packageversioninfo.go | 28 + .../updatesummaries/model_precheckresult.go | 37 ++ .../model_precheckresulttags.go | 9 + .../updatesummaries/model_updatesummaries.go | 17 + .../model_updatesummariesproperties.go | 60 +++ .../updatesummaries/predicates.go | 32 ++ .../updatesummaries/version.go | 12 + 245 files changed, 19554 insertions(+) create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingscreate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsdelete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsget.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingslistbycluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsupdate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_consentandinstalldefaultextensions.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_createidentity.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_generatepassword.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_initializedisableprocess.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponse.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponseproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatch.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatchproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_defaultextensiondetails.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_passwordcredential.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_pernodestate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/arcsettings/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/method_createidentity.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/method_extendsoftwareassurancebenefit.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/method_uploadcertificate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterdesiredproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponse.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponseproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusternode.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterreportedproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_isolatedvmattestationconfiguration.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_rawcertificatedata.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequest.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequestproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassuranceproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/model_uploadcertificaterequest.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/cluster/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_create.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbyresourcegroup.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbysubscription.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/method_update.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterdesiredproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusternode.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatch.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatchproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterreportedproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_isolatedvmattestationconfiguration.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/model_softwareassuranceproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/clusters/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_createorupdate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_listbyclusters.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_adapterpropertyoverrides.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentconfiguration.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentdata.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsettingsproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentstatus.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_hostnetwork.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_infrastructurenetwork.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_intents.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_ippools.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_observability.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_optionalservices.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_physicalnodes.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_qospolicyoverrides.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_reportedproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_scaleunits.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_securitysettings.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_step.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storage.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storagenetworks.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_validationstatus.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_virtualswitchconfigurationoverrides.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_createorupdate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_list.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_validate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_deviceconfiguration.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedevice.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedeviceproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_nicdetail.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validaterequest.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validateresponse.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/edgedevices/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_create.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_listbyarcsetting.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_update.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/method_upgrade.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extension.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceview.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceviewstatus.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionparameters.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatch.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchparameters.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionupgradeparameters.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/model_pernodeextensionstate.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/extensions/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbycluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbypublisher.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/model_offer.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/model_offerproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/model_skumappings.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/offers/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/method_listbycluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisher.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisherproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/publishers/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skusget.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skuslistbyoffer.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/model_sku.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skumappings.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skuproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/skuses/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_list.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_put.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_step.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterun.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterunproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updateruns/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/id_update.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/id_update_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/method_list.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/method_post.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/method_put.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_packageversioninfo.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresult.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresulttags.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_update.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateprerequisite.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/model_updatestateproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updates/version.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/README.md create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/client.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/constants.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster_test.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_delete.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_get.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_list.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_put.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_packageversioninfo.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresult.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresulttags.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummaries.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummariesproperties.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/predicates.go create mode 100644 resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/version.go diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/README.md b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/README.md new file mode 100644 index 00000000000..2b46df0ea4e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/README.md @@ -0,0 +1,163 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/arcsettings` Documentation + +The `arcsettings` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/arcsettings" +``` + + +### Client Initialization + +```go +client := arcsettings.NewArcSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ArcSettingsClient.ArcSettingsCreate` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +payload := arcsettings.ArcSetting{ + // ... +} + + +read, err := client.ArcSettingsCreate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArcSettingsClient.ArcSettingsDelete` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +if err := client.ArcSettingsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArcSettingsClient.ArcSettingsGet` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +read, err := client.ArcSettingsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArcSettingsClient.ArcSettingsListByCluster` + +```go +ctx := context.TODO() +id := arcsettings.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// alternatively `client.ArcSettingsListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.ArcSettingsListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ArcSettingsClient.ArcSettingsUpdate` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +payload := arcsettings.ArcSettingsPatch{ + // ... +} + + +read, err := client.ArcSettingsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArcSettingsClient.ConsentAndInstallDefaultExtensions` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +read, err := client.ConsentAndInstallDefaultExtensions(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArcSettingsClient.CreateIdentity` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +if err := client.CreateIdentityThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArcSettingsClient.GeneratePassword` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +read, err := client.GeneratePassword(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArcSettingsClient.InitializeDisableProcess` + +```go +ctx := context.TODO() +id := arcsettings.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +if err := client.InitializeDisableProcessThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/client.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/client.go new file mode 100644 index 00000000000..bf76b03a6da --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/client.go @@ -0,0 +1,26 @@ +package arcsettings + +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 ArcSettingsClient struct { + Client *resourcemanager.Client +} + +func NewArcSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*ArcSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "arcsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ArcSettingsClient: %+v", err) + } + + return &ArcSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/constants.go new file mode 100644 index 00000000000..9783fea054f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/constants.go @@ -0,0 +1,277 @@ +package arcsettings + +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 ArcSettingAggregateState string + +const ( + ArcSettingAggregateStateAccepted ArcSettingAggregateState = "Accepted" + ArcSettingAggregateStateCanceled ArcSettingAggregateState = "Canceled" + ArcSettingAggregateStateConnected ArcSettingAggregateState = "Connected" + ArcSettingAggregateStateCreating ArcSettingAggregateState = "Creating" + ArcSettingAggregateStateDeleted ArcSettingAggregateState = "Deleted" + ArcSettingAggregateStateDeleting ArcSettingAggregateState = "Deleting" + ArcSettingAggregateStateDisableInProgress ArcSettingAggregateState = "DisableInProgress" + ArcSettingAggregateStateDisconnected ArcSettingAggregateState = "Disconnected" + ArcSettingAggregateStateError ArcSettingAggregateState = "Error" + ArcSettingAggregateStateFailed ArcSettingAggregateState = "Failed" + ArcSettingAggregateStateInProgress ArcSettingAggregateState = "InProgress" + ArcSettingAggregateStateMoving ArcSettingAggregateState = "Moving" + ArcSettingAggregateStateNotSpecified ArcSettingAggregateState = "NotSpecified" + ArcSettingAggregateStatePartiallyConnected ArcSettingAggregateState = "PartiallyConnected" + ArcSettingAggregateStatePartiallySucceeded ArcSettingAggregateState = "PartiallySucceeded" + ArcSettingAggregateStateProvisioning ArcSettingAggregateState = "Provisioning" + ArcSettingAggregateStateSucceeded ArcSettingAggregateState = "Succeeded" + ArcSettingAggregateStateUpdating ArcSettingAggregateState = "Updating" +) + +func PossibleValuesForArcSettingAggregateState() []string { + return []string{ + string(ArcSettingAggregateStateAccepted), + string(ArcSettingAggregateStateCanceled), + string(ArcSettingAggregateStateConnected), + string(ArcSettingAggregateStateCreating), + string(ArcSettingAggregateStateDeleted), + string(ArcSettingAggregateStateDeleting), + string(ArcSettingAggregateStateDisableInProgress), + string(ArcSettingAggregateStateDisconnected), + string(ArcSettingAggregateStateError), + string(ArcSettingAggregateStateFailed), + string(ArcSettingAggregateStateInProgress), + string(ArcSettingAggregateStateMoving), + string(ArcSettingAggregateStateNotSpecified), + string(ArcSettingAggregateStatePartiallyConnected), + string(ArcSettingAggregateStatePartiallySucceeded), + string(ArcSettingAggregateStateProvisioning), + string(ArcSettingAggregateStateSucceeded), + string(ArcSettingAggregateStateUpdating), + } +} + +func (s *ArcSettingAggregateState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseArcSettingAggregateState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseArcSettingAggregateState(input string) (*ArcSettingAggregateState, error) { + vals := map[string]ArcSettingAggregateState{ + "accepted": ArcSettingAggregateStateAccepted, + "canceled": ArcSettingAggregateStateCanceled, + "connected": ArcSettingAggregateStateConnected, + "creating": ArcSettingAggregateStateCreating, + "deleted": ArcSettingAggregateStateDeleted, + "deleting": ArcSettingAggregateStateDeleting, + "disableinprogress": ArcSettingAggregateStateDisableInProgress, + "disconnected": ArcSettingAggregateStateDisconnected, + "error": ArcSettingAggregateStateError, + "failed": ArcSettingAggregateStateFailed, + "inprogress": ArcSettingAggregateStateInProgress, + "moving": ArcSettingAggregateStateMoving, + "notspecified": ArcSettingAggregateStateNotSpecified, + "partiallyconnected": ArcSettingAggregateStatePartiallyConnected, + "partiallysucceeded": ArcSettingAggregateStatePartiallySucceeded, + "provisioning": ArcSettingAggregateStateProvisioning, + "succeeded": ArcSettingAggregateStateSucceeded, + "updating": ArcSettingAggregateStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ArcSettingAggregateState(input) + return &out, nil +} + +type NodeArcState string + +const ( + NodeArcStateAccepted NodeArcState = "Accepted" + NodeArcStateCanceled NodeArcState = "Canceled" + NodeArcStateConnected NodeArcState = "Connected" + NodeArcStateCreating NodeArcState = "Creating" + NodeArcStateDeleted NodeArcState = "Deleted" + NodeArcStateDeleting NodeArcState = "Deleting" + NodeArcStateDisableInProgress NodeArcState = "DisableInProgress" + NodeArcStateDisconnected NodeArcState = "Disconnected" + NodeArcStateError NodeArcState = "Error" + NodeArcStateFailed NodeArcState = "Failed" + NodeArcStateInProgress NodeArcState = "InProgress" + NodeArcStateMoving NodeArcState = "Moving" + NodeArcStateNotSpecified NodeArcState = "NotSpecified" + NodeArcStatePartiallyConnected NodeArcState = "PartiallyConnected" + NodeArcStatePartiallySucceeded NodeArcState = "PartiallySucceeded" + NodeArcStateProvisioning NodeArcState = "Provisioning" + NodeArcStateSucceeded NodeArcState = "Succeeded" + NodeArcStateUpdating NodeArcState = "Updating" +) + +func PossibleValuesForNodeArcState() []string { + return []string{ + string(NodeArcStateAccepted), + string(NodeArcStateCanceled), + string(NodeArcStateConnected), + string(NodeArcStateCreating), + string(NodeArcStateDeleted), + string(NodeArcStateDeleting), + string(NodeArcStateDisableInProgress), + string(NodeArcStateDisconnected), + string(NodeArcStateError), + string(NodeArcStateFailed), + string(NodeArcStateInProgress), + string(NodeArcStateMoving), + string(NodeArcStateNotSpecified), + string(NodeArcStatePartiallyConnected), + string(NodeArcStatePartiallySucceeded), + string(NodeArcStateProvisioning), + string(NodeArcStateSucceeded), + string(NodeArcStateUpdating), + } +} + +func (s *NodeArcState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNodeArcState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNodeArcState(input string) (*NodeArcState, error) { + vals := map[string]NodeArcState{ + "accepted": NodeArcStateAccepted, + "canceled": NodeArcStateCanceled, + "connected": NodeArcStateConnected, + "creating": NodeArcStateCreating, + "deleted": NodeArcStateDeleted, + "deleting": NodeArcStateDeleting, + "disableinprogress": NodeArcStateDisableInProgress, + "disconnected": NodeArcStateDisconnected, + "error": NodeArcStateError, + "failed": NodeArcStateFailed, + "inprogress": NodeArcStateInProgress, + "moving": NodeArcStateMoving, + "notspecified": NodeArcStateNotSpecified, + "partiallyconnected": NodeArcStatePartiallyConnected, + "partiallysucceeded": NodeArcStatePartiallySucceeded, + "provisioning": NodeArcStateProvisioning, + "succeeded": NodeArcStateSucceeded, + "updating": NodeArcStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NodeArcState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateConnected ProvisioningState = "Connected" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateDisableInProgress ProvisioningState = "DisableInProgress" + ProvisioningStateDisconnected ProvisioningState = "Disconnected" + ProvisioningStateError ProvisioningState = "Error" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStatePartiallyConnected ProvisioningState = "PartiallyConnected" + ProvisioningStatePartiallySucceeded ProvisioningState = "PartiallySucceeded" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateConnected), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateDisableInProgress), + string(ProvisioningStateDisconnected), + string(ProvisioningStateError), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateMoving), + string(ProvisioningStateNotSpecified), + string(ProvisioningStatePartiallyConnected), + string(ProvisioningStatePartiallySucceeded), + string(ProvisioningStateProvisioning), + 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, + "connected": ProvisioningStateConnected, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "disableinprogress": ProvisioningStateDisableInProgress, + "disconnected": ProvisioningStateDisconnected, + "error": ProvisioningStateError, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "moving": ProvisioningStateMoving, + "notspecified": ProvisioningStateNotSpecified, + "partiallyconnected": ProvisioningStatePartiallyConnected, + "partiallysucceeded": ProvisioningStatePartiallySucceeded, + "provisioning": ProvisioningStateProvisioning, + "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/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting.go new file mode 100644 index 00000000000..ca8353486ad --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting.go @@ -0,0 +1,134 @@ +package arcsettings + +import ( + "fmt" + "strings" + + "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 = &ArcSettingId{} + +// ArcSettingId is a struct representing the Resource ID for a Arc Setting +type ArcSettingId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + ArcSettingName string +} + +// NewArcSettingID returns a new ArcSettingId struct +func NewArcSettingID(subscriptionId string, resourceGroupName string, clusterName string, arcSettingName string) ArcSettingId { + return ArcSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + ArcSettingName: arcSettingName, + } +} + +// ParseArcSettingID parses 'input' into a ArcSettingId +func ParseArcSettingID(input string) (*ArcSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArcSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArcSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseArcSettingIDInsensitively parses 'input' case-insensitively into a ArcSettingId +// note: this method should only be used for API response data and not user input +func ParseArcSettingIDInsensitively(input string) (*ArcSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArcSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArcSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ArcSettingId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.ArcSettingName, ok = input.Parsed["arcSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "arcSettingName", input) + } + + return nil +} + +// ValidateArcSettingID checks that 'input' can be parsed as a Arc Setting ID +func ValidateArcSettingID(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 := ParseArcSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Arc Setting ID +func (id ArcSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/arcSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.ArcSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Arc Setting ID +func (id ArcSettingId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticArcSettings", "arcSettings", "arcSettings"), + resourceids.UserSpecifiedSegment("arcSettingName", "arcSettingValue"), + } +} + +// String returns a human-readable description of this Arc Setting ID +func (id ArcSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Arc Setting Name: %q", id.ArcSettingName), + } + return fmt.Sprintf("Arc Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting_test.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting_test.go new file mode 100644 index 00000000000..ee3f47acf2f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_arcsetting_test.go @@ -0,0 +1,327 @@ +package arcsettings + +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 = &ArcSettingId{} + +func TestNewArcSettingID(t *testing.T) { + id := NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.ArcSettingName != "arcSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ArcSettingName'", id.ArcSettingName, "arcSettingValue") + } +} + +func TestFormatArcSettingID(t *testing.T) { + actual := NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseArcSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArcSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArcSettingID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + } +} + +func TestParseArcSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArcSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + ArcSettingName: "aRcSeTtInGvAlUe", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArcSettingIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + } +} + +func TestSegmentsForArcSettingId(t *testing.T) { + segments := ArcSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ArcSettingId 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/azurestackhci/2023-08-01-preview/arcsettings/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster.go new file mode 100644 index 00000000000..9a103507191 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster.go @@ -0,0 +1,125 @@ +package arcsettings + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster_test.go new file mode 100644 index 00000000000..ca61c45c616 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/id_cluster_test.go @@ -0,0 +1,282 @@ +package arcsettings + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingscreate.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingscreate.go new file mode 100644 index 00000000000..e23e135a7a4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingscreate.go @@ -0,0 +1,58 @@ +package arcsettings + +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 ArcSettingsCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ArcSetting +} + +// ArcSettingsCreate ... +func (c ArcSettingsClient) ArcSettingsCreate(ctx context.Context, id ArcSettingId, input ArcSetting) (result ArcSettingsCreateOperationResponse, 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 ArcSetting + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsdelete.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsdelete.go new file mode 100644 index 00000000000..c7d5b6dd8d0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsdelete.go @@ -0,0 +1,71 @@ +package arcsettings + +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 ArcSettingsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ArcSettingsDelete ... +func (c ArcSettingsClient) ArcSettingsDelete(ctx context.Context, id ArcSettingId) (result ArcSettingsDeleteOperationResponse, 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 +} + +// ArcSettingsDeleteThenPoll performs ArcSettingsDelete then polls until it's completed +func (c ArcSettingsClient) ArcSettingsDeleteThenPoll(ctx context.Context, id ArcSettingId) error { + result, err := c.ArcSettingsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ArcSettingsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ArcSettingsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsget.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsget.go new file mode 100644 index 00000000000..da38efd7c84 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsget.go @@ -0,0 +1,54 @@ +package arcsettings + +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 ArcSettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ArcSetting +} + +// ArcSettingsGet ... +func (c ArcSettingsClient) ArcSettingsGet(ctx context.Context, id ArcSettingId) (result ArcSettingsGetOperationResponse, 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 ArcSetting + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingslistbycluster.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingslistbycluster.go new file mode 100644 index 00000000000..908176e84fa --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingslistbycluster.go @@ -0,0 +1,91 @@ +package arcsettings + +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 ArcSettingsListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ArcSetting +} + +type ArcSettingsListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []ArcSetting +} + +// ArcSettingsListByCluster ... +func (c ArcSettingsClient) ArcSettingsListByCluster(ctx context.Context, id ClusterId) (result ArcSettingsListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/arcSettings", 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 *[]ArcSetting `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ArcSettingsListByClusterComplete retrieves all the results into a single object +func (c ArcSettingsClient) ArcSettingsListByClusterComplete(ctx context.Context, id ClusterId) (ArcSettingsListByClusterCompleteResult, error) { + return c.ArcSettingsListByClusterCompleteMatchingPredicate(ctx, id, ArcSettingOperationPredicate{}) +} + +// ArcSettingsListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ArcSettingsClient) ArcSettingsListByClusterCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate ArcSettingOperationPredicate) (result ArcSettingsListByClusterCompleteResult, err error) { + items := make([]ArcSetting, 0) + + resp, err := c.ArcSettingsListByCluster(ctx, id) + if err != nil { + 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 = ArcSettingsListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsupdate.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsupdate.go new file mode 100644 index 00000000000..6b942fa5f05 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_arcsettingsupdate.go @@ -0,0 +1,58 @@ +package arcsettings + +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 ArcSettingsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ArcSetting +} + +// ArcSettingsUpdate ... +func (c ArcSettingsClient) ArcSettingsUpdate(ctx context.Context, id ArcSettingId, input ArcSettingsPatch) (result ArcSettingsUpdateOperationResponse, 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 ArcSetting + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_consentandinstalldefaultextensions.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_consentandinstalldefaultextensions.go new file mode 100644 index 00000000000..59282809851 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_consentandinstalldefaultextensions.go @@ -0,0 +1,55 @@ +package arcsettings + +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 ConsentAndInstallDefaultExtensionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ArcSetting +} + +// ConsentAndInstallDefaultExtensions ... +func (c ArcSettingsClient) ConsentAndInstallDefaultExtensions(ctx context.Context, id ArcSettingId) (result ConsentAndInstallDefaultExtensionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/consentAndInstallDefaultExtensions", 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 ArcSetting + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_createidentity.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_createidentity.go new file mode 100644 index 00000000000..1a9bc34c033 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_createidentity.go @@ -0,0 +1,71 @@ +package arcsettings + +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 CreateIdentityOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ArcIdentityResponse +} + +// CreateIdentity ... +func (c ArcSettingsClient) CreateIdentity(ctx context.Context, id ArcSettingId) (result CreateIdentityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/createArcIdentity", 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 +} + +// CreateIdentityThenPoll performs CreateIdentity then polls until it's completed +func (c ArcSettingsClient) CreateIdentityThenPoll(ctx context.Context, id ArcSettingId) error { + result, err := c.CreateIdentity(ctx, id) + if err != nil { + return fmt.Errorf("performing CreateIdentity: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateIdentity: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_generatepassword.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_generatepassword.go new file mode 100644 index 00000000000..4f9aaacb077 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_generatepassword.go @@ -0,0 +1,55 @@ +package arcsettings + +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 GeneratePasswordOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PasswordCredential +} + +// GeneratePassword ... +func (c ArcSettingsClient) GeneratePassword(ctx context.Context, id ArcSettingId) (result GeneratePasswordOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generatePassword", 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 PasswordCredential + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_initializedisableprocess.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_initializedisableprocess.go new file mode 100644 index 00000000000..206fd88abb1 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/method_initializedisableprocess.go @@ -0,0 +1,70 @@ +package arcsettings + +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 InitializeDisableProcessOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// InitializeDisableProcess ... +func (c ArcSettingsClient) InitializeDisableProcess(ctx context.Context, id ArcSettingId) (result InitializeDisableProcessOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/initializeDisableProcess", 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 +} + +// InitializeDisableProcessThenPoll performs InitializeDisableProcess then polls until it's completed +func (c ArcSettingsClient) InitializeDisableProcessThenPoll(ctx context.Context, id ArcSettingId) error { + result, err := c.InitializeDisableProcess(ctx, id) + if err != nil { + return fmt.Errorf("performing InitializeDisableProcess: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after InitializeDisableProcess: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponse.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponse.go new file mode 100644 index 00000000000..08d1275ea50 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponse.go @@ -0,0 +1,8 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcIdentityResponse struct { + Properties *ArcIdentityResponseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponseproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponseproperties.go new file mode 100644 index 00000000000..4e33abb10de --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcidentityresponseproperties.go @@ -0,0 +1,11 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcIdentityResponseProperties struct { + ArcApplicationClientId *string `json:"arcApplicationClientId,omitempty"` + ArcApplicationObjectId *string `json:"arcApplicationObjectId,omitempty"` + ArcApplicationTenantId *string `json:"arcApplicationTenantId,omitempty"` + ArcServicePrincipalObjectId *string `json:"arcServicePrincipalObjectId,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsetting.go new file mode 100644 index 00000000000..792133291a2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsetting.go @@ -0,0 +1,16 @@ +package arcsettings + +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 ArcSetting struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ArcSettingProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingproperties.go new file mode 100644 index 00000000000..436656a1d00 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingproperties.go @@ -0,0 +1,17 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcSettingProperties struct { + AggregateState *ArcSettingAggregateState `json:"aggregateState,omitempty"` + ArcApplicationClientId *string `json:"arcApplicationClientId,omitempty"` + ArcApplicationObjectId *string `json:"arcApplicationObjectId,omitempty"` + ArcApplicationTenantId *string `json:"arcApplicationTenantId,omitempty"` + ArcInstanceResourceGroup *string `json:"arcInstanceResourceGroup,omitempty"` + ArcServicePrincipalObjectId *string `json:"arcServicePrincipalObjectId,omitempty"` + ConnectivityProperties *interface{} `json:"connectivityProperties,omitempty"` + DefaultExtensions *[]DefaultExtensionDetails `json:"defaultExtensions,omitempty"` + PerNodeDetails *[]PerNodeState `json:"perNodeDetails,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatch.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatch.go new file mode 100644 index 00000000000..ff9c88a3664 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatch.go @@ -0,0 +1,9 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcSettingsPatch struct { + Properties *ArcSettingsPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatchproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatchproperties.go new file mode 100644 index 00000000000..7a806bba490 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_arcsettingspatchproperties.go @@ -0,0 +1,8 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcSettingsPatchProperties struct { + ConnectivityProperties *interface{} `json:"connectivityProperties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_defaultextensiondetails.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_defaultextensiondetails.go new file mode 100644 index 00000000000..392d04915bb --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_defaultextensiondetails.go @@ -0,0 +1,27 @@ +package arcsettings + +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 DefaultExtensionDetails struct { + Category *string `json:"category,omitempty"` + ConsentTime *string `json:"consentTime,omitempty"` +} + +func (o *DefaultExtensionDetails) GetConsentTimeAsTime() (*time.Time, error) { + if o.ConsentTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ConsentTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DefaultExtensionDetails) SetConsentTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ConsentTime = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_passwordcredential.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_passwordcredential.go new file mode 100644 index 00000000000..cf56a2624c0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_passwordcredential.go @@ -0,0 +1,41 @@ +package arcsettings + +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 PasswordCredential struct { + EndDateTime *string `json:"endDateTime,omitempty"` + KeyId *string `json:"keyId,omitempty"` + SecretText *string `json:"secretText,omitempty"` + StartDateTime *string `json:"startDateTime,omitempty"` +} + +func (o *PasswordCredential) GetEndDateTimeAsTime() (*time.Time, error) { + if o.EndDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PasswordCredential) SetEndDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDateTime = &formatted +} + +func (o *PasswordCredential) GetStartDateTimeAsTime() (*time.Time, error) { + if o.StartDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PasswordCredential) SetStartDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDateTime = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_pernodestate.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_pernodestate.go new file mode 100644 index 00000000000..9b79465a5d3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/model_pernodestate.go @@ -0,0 +1,11 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PerNodeState struct { + ArcInstance *string `json:"arcInstance,omitempty"` + ArcNodeServicePrincipalObjectId *string `json:"arcNodeServicePrincipalObjectId,omitempty"` + Name *string `json:"name,omitempty"` + State *NodeArcState `json:"state,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/predicates.go new file mode 100644 index 00000000000..98d1fe0a836 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/predicates.go @@ -0,0 +1,27 @@ +package arcsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArcSettingOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ArcSettingOperationPredicate) Matches(input ArcSetting) 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/azurestackhci/2023-08-01-preview/arcsettings/version.go b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/version.go new file mode 100644 index 00000000000..3c8ed4cb113 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/arcsettings/version.go @@ -0,0 +1,12 @@ +package arcsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/arcsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/client.go b/resource-manager/azurestackhci/2023-08-01-preview/client.go new file mode 100644 index 00000000000..dd03bede13f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/client.go @@ -0,0 +1,127 @@ +package v2023_08_01_preview + +// 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/azurestackhci/2023-08-01-preview/arcsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/cluster" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/clusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/edgedevices" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/extensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/offers" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/publishers" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/skuses" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updateruns" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updates" + "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + ArcSettings *arcsettings.ArcSettingsClient + Cluster *cluster.ClusterClient + Clusters *clusters.ClustersClient + DeploymentSettings *deploymentsettings.DeploymentSettingsClient + EdgeDevices *edgedevices.EdgeDevicesClient + Extensions *extensions.ExtensionsClient + Offers *offers.OffersClient + Publishers *publishers.PublishersClient + Skuses *skuses.SkusesClient + UpdateRuns *updateruns.UpdateRunsClient + UpdateSummaries *updatesummaries.UpdateSummariesClient + Updates *updates.UpdatesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + arcSettingsClient, err := arcsettings.NewArcSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ArcSettings client: %+v", err) + } + configureFunc(arcSettingsClient.Client) + + clusterClient, err := cluster.NewClusterClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Cluster client: %+v", err) + } + configureFunc(clusterClient.Client) + + clustersClient, err := clusters.NewClustersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Clusters client: %+v", err) + } + configureFunc(clustersClient.Client) + + deploymentSettingsClient, err := deploymentsettings.NewDeploymentSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeploymentSettings client: %+v", err) + } + configureFunc(deploymentSettingsClient.Client) + + edgeDevicesClient, err := edgedevices.NewEdgeDevicesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EdgeDevices client: %+v", err) + } + configureFunc(edgeDevicesClient.Client) + + extensionsClient, err := extensions.NewExtensionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Extensions client: %+v", err) + } + configureFunc(extensionsClient.Client) + + offersClient, err := offers.NewOffersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Offers client: %+v", err) + } + configureFunc(offersClient.Client) + + publishersClient, err := publishers.NewPublishersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Publishers client: %+v", err) + } + configureFunc(publishersClient.Client) + + skusesClient, err := skuses.NewSkusesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Skuses client: %+v", err) + } + configureFunc(skusesClient.Client) + + updateRunsClient, err := updateruns.NewUpdateRunsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UpdateRuns client: %+v", err) + } + configureFunc(updateRunsClient.Client) + + updateSummariesClient, err := updatesummaries.NewUpdateSummariesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UpdateSummaries client: %+v", err) + } + configureFunc(updateSummariesClient.Client) + + updatesClient, err := updates.NewUpdatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Updates client: %+v", err) + } + configureFunc(updatesClient.Client) + + return &Client{ + ArcSettings: arcSettingsClient, + Cluster: clusterClient, + Clusters: clustersClient, + DeploymentSettings: deploymentSettingsClient, + EdgeDevices: edgeDevicesClient, + Extensions: extensionsClient, + Offers: offersClient, + Publishers: publishersClient, + Skuses: skusesClient, + UpdateRuns: updateRunsClient, + UpdateSummaries: updateSummariesClient, + Updates: updatesClient, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/README.md b/resource-manager/azurestackhci/2023-08-01-preview/cluster/README.md new file mode 100644 index 00000000000..7ea2c435245 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/README.md @@ -0,0 +1,66 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/cluster` Documentation + +The `cluster` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/cluster" +``` + + +### Client Initialization + +```go +client := cluster.NewClusterClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClusterClient.CreateIdentity` + +```go +ctx := context.TODO() +id := cluster.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +if err := client.CreateIdentityThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClusterClient.ExtendSoftwareAssuranceBenefit` + +```go +ctx := context.TODO() +id := cluster.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +payload := cluster.SoftwareAssuranceChangeRequest{ + // ... +} + + +if err := client.ExtendSoftwareAssuranceBenefitThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClusterClient.UploadCertificate` + +```go +ctx := context.TODO() +id := cluster.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +payload := cluster.UploadCertificateRequest{ + // ... +} + + +if err := client.UploadCertificateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/client.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/client.go new file mode 100644 index 00000000000..2a0e60ffb2b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/client.go @@ -0,0 +1,26 @@ +package cluster + +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 ClusterClient struct { + Client *resourcemanager.Client +} + +func NewClusterClientWithBaseURI(sdkApi sdkEnv.Api) (*ClusterClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "cluster", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClusterClient: %+v", err) + } + + return &ClusterClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/constants.go new file mode 100644 index 00000000000..dafab9b8d70 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/constants.go @@ -0,0 +1,510 @@ +package cluster + +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 ClusterNodeType string + +const ( + ClusterNodeTypeFirstParty ClusterNodeType = "FirstParty" + ClusterNodeTypeThirdParty ClusterNodeType = "ThirdParty" +) + +func PossibleValuesForClusterNodeType() []string { + return []string{ + string(ClusterNodeTypeFirstParty), + string(ClusterNodeTypeThirdParty), + } +} + +func (s *ClusterNodeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterNodeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusterNodeType(input string) (*ClusterNodeType, error) { + vals := map[string]ClusterNodeType{ + "firstparty": ClusterNodeTypeFirstParty, + "thirdparty": ClusterNodeTypeThirdParty, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusterNodeType(input) + return &out, nil +} + +type ConnectivityStatus string + +const ( + ConnectivityStatusConnected ConnectivityStatus = "Connected" + ConnectivityStatusDisconnected ConnectivityStatus = "Disconnected" + ConnectivityStatusNotConnectedRecently ConnectivityStatus = "NotConnectedRecently" + ConnectivityStatusNotSpecified ConnectivityStatus = "NotSpecified" + ConnectivityStatusNotYetRegistered ConnectivityStatus = "NotYetRegistered" + ConnectivityStatusPartiallyConnected ConnectivityStatus = "PartiallyConnected" +) + +func PossibleValuesForConnectivityStatus() []string { + return []string{ + string(ConnectivityStatusConnected), + string(ConnectivityStatusDisconnected), + string(ConnectivityStatusNotConnectedRecently), + string(ConnectivityStatusNotSpecified), + string(ConnectivityStatusNotYetRegistered), + string(ConnectivityStatusPartiallyConnected), + } +} + +func (s *ConnectivityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectivityStatus(input string) (*ConnectivityStatus, error) { + vals := map[string]ConnectivityStatus{ + "connected": ConnectivityStatusConnected, + "disconnected": ConnectivityStatusDisconnected, + "notconnectedrecently": ConnectivityStatusNotConnectedRecently, + "notspecified": ConnectivityStatusNotSpecified, + "notyetregistered": ConnectivityStatusNotYetRegistered, + "partiallyconnected": ConnectivityStatusPartiallyConnected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityStatus(input) + return &out, nil +} + +type DiagnosticLevel string + +const ( + DiagnosticLevelBasic DiagnosticLevel = "Basic" + DiagnosticLevelEnhanced DiagnosticLevel = "Enhanced" + DiagnosticLevelOff DiagnosticLevel = "Off" +) + +func PossibleValuesForDiagnosticLevel() []string { + return []string{ + string(DiagnosticLevelBasic), + string(DiagnosticLevelEnhanced), + string(DiagnosticLevelOff), + } +} + +func (s *DiagnosticLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDiagnosticLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDiagnosticLevel(input string) (*DiagnosticLevel, error) { + vals := map[string]DiagnosticLevel{ + "basic": DiagnosticLevelBasic, + "enhanced": DiagnosticLevelEnhanced, + "off": DiagnosticLevelOff, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiagnosticLevel(input) + return &out, nil +} + +type ImdsAttestation string + +const ( + ImdsAttestationDisabled ImdsAttestation = "Disabled" + ImdsAttestationEnabled ImdsAttestation = "Enabled" +) + +func PossibleValuesForImdsAttestation() []string { + return []string{ + string(ImdsAttestationDisabled), + string(ImdsAttestationEnabled), + } +} + +func (s *ImdsAttestation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImdsAttestation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImdsAttestation(input string) (*ImdsAttestation, error) { + vals := map[string]ImdsAttestation{ + "disabled": ImdsAttestationDisabled, + "enabled": ImdsAttestationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImdsAttestation(input) + return &out, nil +} + +type OemActivation string + +const ( + OemActivationDisabled OemActivation = "Disabled" + OemActivationEnabled OemActivation = "Enabled" +) + +func PossibleValuesForOemActivation() []string { + return []string{ + string(OemActivationDisabled), + string(OemActivationEnabled), + } +} + +func (s *OemActivation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOemActivation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOemActivation(input string) (*OemActivation, error) { + vals := map[string]OemActivation{ + "disabled": OemActivationDisabled, + "enabled": OemActivationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OemActivation(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateConnected ProvisioningState = "Connected" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateDisableInProgress ProvisioningState = "DisableInProgress" + ProvisioningStateDisconnected ProvisioningState = "Disconnected" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStatePartiallyConnected ProvisioningState = "PartiallyConnected" + ProvisioningStatePartiallySucceeded ProvisioningState = "PartiallySucceeded" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateConnected), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateDisableInProgress), + string(ProvisioningStateDisconnected), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateMoving), + string(ProvisioningStateNotSpecified), + string(ProvisioningStatePartiallyConnected), + string(ProvisioningStatePartiallySucceeded), + string(ProvisioningStateProvisioning), + 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, + "connected": ProvisioningStateConnected, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "disableinprogress": ProvisioningStateDisableInProgress, + "disconnected": ProvisioningStateDisconnected, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "moving": ProvisioningStateMoving, + "notspecified": ProvisioningStateNotSpecified, + "partiallyconnected": ProvisioningStatePartiallyConnected, + "partiallysucceeded": ProvisioningStatePartiallySucceeded, + "provisioning": ProvisioningStateProvisioning, + "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 SoftwareAssuranceIntent string + +const ( + SoftwareAssuranceIntentDisable SoftwareAssuranceIntent = "Disable" + SoftwareAssuranceIntentEnable SoftwareAssuranceIntent = "Enable" +) + +func PossibleValuesForSoftwareAssuranceIntent() []string { + return []string{ + string(SoftwareAssuranceIntentDisable), + string(SoftwareAssuranceIntentEnable), + } +} + +func (s *SoftwareAssuranceIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftwareAssuranceIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftwareAssuranceIntent(input string) (*SoftwareAssuranceIntent, error) { + vals := map[string]SoftwareAssuranceIntent{ + "disable": SoftwareAssuranceIntentDisable, + "enable": SoftwareAssuranceIntentEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftwareAssuranceIntent(input) + return &out, nil +} + +type SoftwareAssuranceStatus string + +const ( + SoftwareAssuranceStatusDisabled SoftwareAssuranceStatus = "Disabled" + SoftwareAssuranceStatusEnabled SoftwareAssuranceStatus = "Enabled" +) + +func PossibleValuesForSoftwareAssuranceStatus() []string { + return []string{ + string(SoftwareAssuranceStatusDisabled), + string(SoftwareAssuranceStatusEnabled), + } +} + +func (s *SoftwareAssuranceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftwareAssuranceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftwareAssuranceStatus(input string) (*SoftwareAssuranceStatus, error) { + vals := map[string]SoftwareAssuranceStatus{ + "disabled": SoftwareAssuranceStatusDisabled, + "enabled": SoftwareAssuranceStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftwareAssuranceStatus(input) + return &out, nil +} + +type Status string + +const ( + StatusConnectedRecently Status = "ConnectedRecently" + StatusDeploymentFailed Status = "DeploymentFailed" + StatusDeploymentInProgress Status = "DeploymentInProgress" + StatusDeploymentSuccess Status = "DeploymentSuccess" + StatusDisconnected Status = "Disconnected" + StatusError Status = "Error" + StatusNotConnectedRecently Status = "NotConnectedRecently" + StatusNotSpecified Status = "NotSpecified" + StatusNotYetRegistered Status = "NotYetRegistered" + StatusValidationFailed Status = "ValidationFailed" + StatusValidationInProgress Status = "ValidationInProgress" + StatusValidationSuccess Status = "ValidationSuccess" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConnectedRecently), + string(StatusDeploymentFailed), + string(StatusDeploymentInProgress), + string(StatusDeploymentSuccess), + string(StatusDisconnected), + string(StatusError), + string(StatusNotConnectedRecently), + string(StatusNotSpecified), + string(StatusNotYetRegistered), + string(StatusValidationFailed), + string(StatusValidationInProgress), + string(StatusValidationSuccess), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "connectedrecently": StatusConnectedRecently, + "deploymentfailed": StatusDeploymentFailed, + "deploymentinprogress": StatusDeploymentInProgress, + "deploymentsuccess": StatusDeploymentSuccess, + "disconnected": StatusDisconnected, + "error": StatusError, + "notconnectedrecently": StatusNotConnectedRecently, + "notspecified": StatusNotSpecified, + "notyetregistered": StatusNotYetRegistered, + "validationfailed": StatusValidationFailed, + "validationinprogress": StatusValidationInProgress, + "validationsuccess": StatusValidationSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type WindowsServerSubscription string + +const ( + WindowsServerSubscriptionDisabled WindowsServerSubscription = "Disabled" + WindowsServerSubscriptionEnabled WindowsServerSubscription = "Enabled" +) + +func PossibleValuesForWindowsServerSubscription() []string { + return []string{ + string(WindowsServerSubscriptionDisabled), + string(WindowsServerSubscriptionEnabled), + } +} + +func (s *WindowsServerSubscription) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWindowsServerSubscription(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWindowsServerSubscription(input string) (*WindowsServerSubscription, error) { + vals := map[string]WindowsServerSubscription{ + "disabled": WindowsServerSubscriptionDisabled, + "enabled": WindowsServerSubscriptionEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WindowsServerSubscription(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster.go new file mode 100644 index 00000000000..412e376a19e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster.go @@ -0,0 +1,125 @@ +package cluster + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster_test.go new file mode 100644 index 00000000000..9b70ca2f6bd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/id_cluster_test.go @@ -0,0 +1,282 @@ +package cluster + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/cluster/method_createidentity.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_createidentity.go new file mode 100644 index 00000000000..76c9822e828 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_createidentity.go @@ -0,0 +1,71 @@ +package cluster + +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 CreateIdentityOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ClusterIdentityResponse +} + +// CreateIdentity ... +func (c ClusterClient) CreateIdentity(ctx context.Context, id ClusterId) (result CreateIdentityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/createClusterIdentity", 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 +} + +// CreateIdentityThenPoll performs CreateIdentity then polls until it's completed +func (c ClusterClient) CreateIdentityThenPoll(ctx context.Context, id ClusterId) error { + result, err := c.CreateIdentity(ctx, id) + if err != nil { + return fmt.Errorf("performing CreateIdentity: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateIdentity: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_extendsoftwareassurancebenefit.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_extendsoftwareassurancebenefit.go new file mode 100644 index 00000000000..3e2ec35d364 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_extendsoftwareassurancebenefit.go @@ -0,0 +1,75 @@ +package cluster + +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 ExtendSoftwareAssuranceBenefitOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// ExtendSoftwareAssuranceBenefit ... +func (c ClusterClient) ExtendSoftwareAssuranceBenefit(ctx context.Context, id ClusterId, input SoftwareAssuranceChangeRequest) (result ExtendSoftwareAssuranceBenefitOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/extendSoftwareAssuranceBenefit", 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 +} + +// ExtendSoftwareAssuranceBenefitThenPoll performs ExtendSoftwareAssuranceBenefit then polls until it's completed +func (c ClusterClient) ExtendSoftwareAssuranceBenefitThenPoll(ctx context.Context, id ClusterId, input SoftwareAssuranceChangeRequest) error { + result, err := c.ExtendSoftwareAssuranceBenefit(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ExtendSoftwareAssuranceBenefit: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExtendSoftwareAssuranceBenefit: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_uploadcertificate.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_uploadcertificate.go new file mode 100644 index 00000000000..7bf2cea2c85 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/method_uploadcertificate.go @@ -0,0 +1,73 @@ +package cluster + +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 UploadCertificateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// UploadCertificate ... +func (c ClusterClient) UploadCertificate(ctx context.Context, id ClusterId, input UploadCertificateRequest) (result UploadCertificateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/uploadCertificate", 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 +} + +// UploadCertificateThenPoll performs UploadCertificate then polls until it's completed +func (c ClusterClient) UploadCertificateThenPoll(ctx context.Context, id ClusterId, input UploadCertificateRequest) error { + result, err := c.UploadCertificate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UploadCertificate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UploadCertificate: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_cluster.go new file mode 100644 index 00000000000..e41f174485b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_cluster.go @@ -0,0 +1,20 @@ +package cluster + +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 Cluster struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `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/azurestackhci/2023-08-01-preview/cluster/model_clusterdesiredproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterdesiredproperties.go new file mode 100644 index 00000000000..7ff21e52a48 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterdesiredproperties.go @@ -0,0 +1,9 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterDesiredProperties struct { + DiagnosticLevel *DiagnosticLevel `json:"diagnosticLevel,omitempty"` + WindowsServerSubscription *WindowsServerSubscription `json:"windowsServerSubscription,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponse.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponse.go new file mode 100644 index 00000000000..7e64cb4e35a --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponse.go @@ -0,0 +1,8 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterIdentityResponse struct { + Properties *ClusterIdentityResponseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponseproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponseproperties.go new file mode 100644 index 00000000000..1ba7404ca10 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusteridentityresponseproperties.go @@ -0,0 +1,11 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterIdentityResponseProperties struct { + AadApplicationObjectId *string `json:"aadApplicationObjectId,omitempty"` + AadClientId *string `json:"aadClientId,omitempty"` + AadServicePrincipalObjectId *string `json:"aadServicePrincipalObjectId,omitempty"` + AadTenantId *string `json:"aadTenantId,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusternode.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusternode.go new file mode 100644 index 00000000000..ed63418454c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusternode.go @@ -0,0 +1,40 @@ +package cluster + +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 ClusterNode struct { + CoreCount *float64 `json:"coreCount,omitempty"` + EhcResourceId *string `json:"ehcResourceId,omitempty"` + Id *float64 `json:"id,omitempty"` + LastLicensingTimestamp *string `json:"lastLicensingTimestamp,omitempty"` + Manufacturer *string `json:"manufacturer,omitempty"` + MemoryInGiB *float64 `json:"memoryInGiB,omitempty"` + Model *string `json:"model,omitempty"` + Name *string `json:"name,omitempty"` + NodeType *ClusterNodeType `json:"nodeType,omitempty"` + OemActivation *OemActivation `json:"oemActivation,omitempty"` + OsDisplayVersion *string `json:"osDisplayVersion,omitempty"` + OsName *string `json:"osName,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + SerialNumber *string `json:"serialNumber,omitempty"` + WindowsServerSubscription *WindowsServerSubscription `json:"windowsServerSubscription,omitempty"` +} + +func (o *ClusterNode) GetLastLicensingTimestampAsTime() (*time.Time, error) { + if o.LastLicensingTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastLicensingTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterNode) SetLastLicensingTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastLicensingTimestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterproperties.go new file mode 100644 index 00000000000..bf4887b14dd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterproperties.go @@ -0,0 +1,69 @@ +package cluster + +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 ClusterProperties struct { + AadApplicationObjectId *string `json:"aadApplicationObjectId,omitempty"` + AadClientId *string `json:"aadClientId,omitempty"` + AadServicePrincipalObjectId *string `json:"aadServicePrincipalObjectId,omitempty"` + AadTenantId *string `json:"aadTenantId,omitempty"` + BillingModel *string `json:"billingModel,omitempty"` + CloudId *string `json:"cloudId,omitempty"` + CloudManagementEndpoint *string `json:"cloudManagementEndpoint,omitempty"` + ConnectivityStatus *ConnectivityStatus `json:"connectivityStatus,omitempty"` + DesiredProperties *ClusterDesiredProperties `json:"desiredProperties,omitempty"` + IsolatedVMAttestationConfiguration *IsolatedVMAttestationConfiguration `json:"isolatedVmAttestationConfiguration,omitempty"` + LastBillingTimestamp *string `json:"lastBillingTimestamp,omitempty"` + LastSyncTimestamp *string `json:"lastSyncTimestamp,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RegistrationTimestamp *string `json:"registrationTimestamp,omitempty"` + ReportedProperties *ClusterReportedProperties `json:"reportedProperties,omitempty"` + ResourceProviderObjectId *string `json:"resourceProviderObjectId,omitempty"` + ServiceEndpoint *string `json:"serviceEndpoint,omitempty"` + SoftwareAssuranceProperties *SoftwareAssuranceProperties `json:"softwareAssuranceProperties,omitempty"` + Status *Status `json:"status,omitempty"` + TrialDaysRemaining *float64 `json:"trialDaysRemaining,omitempty"` +} + +func (o *ClusterProperties) GetLastBillingTimestampAsTime() (*time.Time, error) { + if o.LastBillingTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastBillingTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetLastBillingTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastBillingTimestamp = &formatted +} + +func (o *ClusterProperties) GetLastSyncTimestampAsTime() (*time.Time, error) { + if o.LastSyncTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetLastSyncTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTimestamp = &formatted +} + +func (o *ClusterProperties) GetRegistrationTimestampAsTime() (*time.Time, error) { + if o.RegistrationTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegistrationTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetRegistrationTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegistrationTimestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterreportedproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterreportedproperties.go new file mode 100644 index 00000000000..bf51621f6ad --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_clusterreportedproperties.go @@ -0,0 +1,36 @@ +package cluster + +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 ClusterReportedProperties struct { + ClusterId *string `json:"clusterId,omitempty"` + ClusterName *string `json:"clusterName,omitempty"` + ClusterType *ClusterNodeType `json:"clusterType,omitempty"` + ClusterVersion *string `json:"clusterVersion,omitempty"` + DiagnosticLevel *DiagnosticLevel `json:"diagnosticLevel,omitempty"` + ImdsAttestation *ImdsAttestation `json:"imdsAttestation,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + Manufacturer *string `json:"manufacturer,omitempty"` + Nodes *[]ClusterNode `json:"nodes,omitempty"` + OemActivation *OemActivation `json:"oemActivation,omitempty"` + SupportedCapabilities *[]string `json:"supportedCapabilities,omitempty"` +} + +func (o *ClusterReportedProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterReportedProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_isolatedvmattestationconfiguration.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_isolatedvmattestationconfiguration.go new file mode 100644 index 00000000000..878a67cd16c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_isolatedvmattestationconfiguration.go @@ -0,0 +1,10 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IsolatedVMAttestationConfiguration struct { + AttestationResourceId *string `json:"attestationResourceId,omitempty"` + AttestationServiceEndpoint *string `json:"attestationServiceEndpoint,omitempty"` + RelyingPartyServiceEndpoint *string `json:"relyingPartyServiceEndpoint,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_rawcertificatedata.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_rawcertificatedata.go new file mode 100644 index 00000000000..d2a4c0aa21f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_rawcertificatedata.go @@ -0,0 +1,8 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RawCertificateData struct { + Certificates *[]string `json:"certificates,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequest.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequest.go new file mode 100644 index 00000000000..61ed38159fe --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequest.go @@ -0,0 +1,8 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftwareAssuranceChangeRequest struct { + Properties *SoftwareAssuranceChangeRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequestproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequestproperties.go new file mode 100644 index 00000000000..b7dd0dcb80c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassurancechangerequestproperties.go @@ -0,0 +1,8 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftwareAssuranceChangeRequestProperties struct { + SoftwareAssuranceIntent *SoftwareAssuranceIntent `json:"softwareAssuranceIntent,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassuranceproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassuranceproperties.go new file mode 100644 index 00000000000..671a0e62dee --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_softwareassuranceproperties.go @@ -0,0 +1,28 @@ +package cluster + +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 SoftwareAssuranceProperties struct { + LastUpdated *string `json:"lastUpdated,omitempty"` + SoftwareAssuranceIntent *SoftwareAssuranceIntent `json:"softwareAssuranceIntent,omitempty"` + SoftwareAssuranceStatus *SoftwareAssuranceStatus `json:"softwareAssuranceStatus,omitempty"` +} + +func (o *SoftwareAssuranceProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SoftwareAssuranceProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_uploadcertificaterequest.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_uploadcertificaterequest.go new file mode 100644 index 00000000000..fc979a96d24 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/model_uploadcertificaterequest.go @@ -0,0 +1,8 @@ +package cluster + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UploadCertificateRequest struct { + Properties *RawCertificateData `json:"properties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/cluster/version.go b/resource-manager/azurestackhci/2023-08-01-preview/cluster/version.go new file mode 100644 index 00000000000..3e343252347 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/cluster/version.go @@ -0,0 +1,12 @@ +package cluster + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/cluster/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/README.md b/resource-manager/azurestackhci/2023-08-01-preview/clusters/README.md new file mode 100644 index 00000000000..fced02ee849 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/README.md @@ -0,0 +1,125 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/clusters` Documentation + +The `clusters` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/clusters" +``` + + +### Client Initialization + +```go +client := clusters.NewClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClustersClient.Create` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +payload := clusters.Cluster{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ClustersClient.Delete` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClustersClient.Get` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +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: `ClustersClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ClustersClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ClustersClient.Update` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +payload := clusters.ClusterPatch{ + // ... +} + + +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/azurestackhci/2023-08-01-preview/clusters/client.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/client.go new file mode 100644 index 00000000000..e4ab7fd89ad --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/client.go @@ -0,0 +1,26 @@ +package clusters + +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 ClustersClient struct { + Client *resourcemanager.Client +} + +func NewClustersClientWithBaseURI(sdkApi sdkEnv.Api) (*ClustersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "clusters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClustersClient: %+v", err) + } + + return &ClustersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/constants.go new file mode 100644 index 00000000000..134cb526978 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/constants.go @@ -0,0 +1,510 @@ +package clusters + +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 ClusterNodeType string + +const ( + ClusterNodeTypeFirstParty ClusterNodeType = "FirstParty" + ClusterNodeTypeThirdParty ClusterNodeType = "ThirdParty" +) + +func PossibleValuesForClusterNodeType() []string { + return []string{ + string(ClusterNodeTypeFirstParty), + string(ClusterNodeTypeThirdParty), + } +} + +func (s *ClusterNodeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterNodeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusterNodeType(input string) (*ClusterNodeType, error) { + vals := map[string]ClusterNodeType{ + "firstparty": ClusterNodeTypeFirstParty, + "thirdparty": ClusterNodeTypeThirdParty, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusterNodeType(input) + return &out, nil +} + +type ConnectivityStatus string + +const ( + ConnectivityStatusConnected ConnectivityStatus = "Connected" + ConnectivityStatusDisconnected ConnectivityStatus = "Disconnected" + ConnectivityStatusNotConnectedRecently ConnectivityStatus = "NotConnectedRecently" + ConnectivityStatusNotSpecified ConnectivityStatus = "NotSpecified" + ConnectivityStatusNotYetRegistered ConnectivityStatus = "NotYetRegistered" + ConnectivityStatusPartiallyConnected ConnectivityStatus = "PartiallyConnected" +) + +func PossibleValuesForConnectivityStatus() []string { + return []string{ + string(ConnectivityStatusConnected), + string(ConnectivityStatusDisconnected), + string(ConnectivityStatusNotConnectedRecently), + string(ConnectivityStatusNotSpecified), + string(ConnectivityStatusNotYetRegistered), + string(ConnectivityStatusPartiallyConnected), + } +} + +func (s *ConnectivityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectivityStatus(input string) (*ConnectivityStatus, error) { + vals := map[string]ConnectivityStatus{ + "connected": ConnectivityStatusConnected, + "disconnected": ConnectivityStatusDisconnected, + "notconnectedrecently": ConnectivityStatusNotConnectedRecently, + "notspecified": ConnectivityStatusNotSpecified, + "notyetregistered": ConnectivityStatusNotYetRegistered, + "partiallyconnected": ConnectivityStatusPartiallyConnected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityStatus(input) + return &out, nil +} + +type DiagnosticLevel string + +const ( + DiagnosticLevelBasic DiagnosticLevel = "Basic" + DiagnosticLevelEnhanced DiagnosticLevel = "Enhanced" + DiagnosticLevelOff DiagnosticLevel = "Off" +) + +func PossibleValuesForDiagnosticLevel() []string { + return []string{ + string(DiagnosticLevelBasic), + string(DiagnosticLevelEnhanced), + string(DiagnosticLevelOff), + } +} + +func (s *DiagnosticLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDiagnosticLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDiagnosticLevel(input string) (*DiagnosticLevel, error) { + vals := map[string]DiagnosticLevel{ + "basic": DiagnosticLevelBasic, + "enhanced": DiagnosticLevelEnhanced, + "off": DiagnosticLevelOff, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiagnosticLevel(input) + return &out, nil +} + +type ImdsAttestation string + +const ( + ImdsAttestationDisabled ImdsAttestation = "Disabled" + ImdsAttestationEnabled ImdsAttestation = "Enabled" +) + +func PossibleValuesForImdsAttestation() []string { + return []string{ + string(ImdsAttestationDisabled), + string(ImdsAttestationEnabled), + } +} + +func (s *ImdsAttestation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImdsAttestation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImdsAttestation(input string) (*ImdsAttestation, error) { + vals := map[string]ImdsAttestation{ + "disabled": ImdsAttestationDisabled, + "enabled": ImdsAttestationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImdsAttestation(input) + return &out, nil +} + +type OemActivation string + +const ( + OemActivationDisabled OemActivation = "Disabled" + OemActivationEnabled OemActivation = "Enabled" +) + +func PossibleValuesForOemActivation() []string { + return []string{ + string(OemActivationDisabled), + string(OemActivationEnabled), + } +} + +func (s *OemActivation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOemActivation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOemActivation(input string) (*OemActivation, error) { + vals := map[string]OemActivation{ + "disabled": OemActivationDisabled, + "enabled": OemActivationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OemActivation(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateConnected ProvisioningState = "Connected" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateDisableInProgress ProvisioningState = "DisableInProgress" + ProvisioningStateDisconnected ProvisioningState = "Disconnected" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStatePartiallyConnected ProvisioningState = "PartiallyConnected" + ProvisioningStatePartiallySucceeded ProvisioningState = "PartiallySucceeded" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateConnected), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateDisableInProgress), + string(ProvisioningStateDisconnected), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateMoving), + string(ProvisioningStateNotSpecified), + string(ProvisioningStatePartiallyConnected), + string(ProvisioningStatePartiallySucceeded), + string(ProvisioningStateProvisioning), + 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, + "connected": ProvisioningStateConnected, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "disableinprogress": ProvisioningStateDisableInProgress, + "disconnected": ProvisioningStateDisconnected, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "moving": ProvisioningStateMoving, + "notspecified": ProvisioningStateNotSpecified, + "partiallyconnected": ProvisioningStatePartiallyConnected, + "partiallysucceeded": ProvisioningStatePartiallySucceeded, + "provisioning": ProvisioningStateProvisioning, + "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 SoftwareAssuranceIntent string + +const ( + SoftwareAssuranceIntentDisable SoftwareAssuranceIntent = "Disable" + SoftwareAssuranceIntentEnable SoftwareAssuranceIntent = "Enable" +) + +func PossibleValuesForSoftwareAssuranceIntent() []string { + return []string{ + string(SoftwareAssuranceIntentDisable), + string(SoftwareAssuranceIntentEnable), + } +} + +func (s *SoftwareAssuranceIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftwareAssuranceIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftwareAssuranceIntent(input string) (*SoftwareAssuranceIntent, error) { + vals := map[string]SoftwareAssuranceIntent{ + "disable": SoftwareAssuranceIntentDisable, + "enable": SoftwareAssuranceIntentEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftwareAssuranceIntent(input) + return &out, nil +} + +type SoftwareAssuranceStatus string + +const ( + SoftwareAssuranceStatusDisabled SoftwareAssuranceStatus = "Disabled" + SoftwareAssuranceStatusEnabled SoftwareAssuranceStatus = "Enabled" +) + +func PossibleValuesForSoftwareAssuranceStatus() []string { + return []string{ + string(SoftwareAssuranceStatusDisabled), + string(SoftwareAssuranceStatusEnabled), + } +} + +func (s *SoftwareAssuranceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftwareAssuranceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftwareAssuranceStatus(input string) (*SoftwareAssuranceStatus, error) { + vals := map[string]SoftwareAssuranceStatus{ + "disabled": SoftwareAssuranceStatusDisabled, + "enabled": SoftwareAssuranceStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftwareAssuranceStatus(input) + return &out, nil +} + +type Status string + +const ( + StatusConnectedRecently Status = "ConnectedRecently" + StatusDeploymentFailed Status = "DeploymentFailed" + StatusDeploymentInProgress Status = "DeploymentInProgress" + StatusDeploymentSuccess Status = "DeploymentSuccess" + StatusDisconnected Status = "Disconnected" + StatusError Status = "Error" + StatusNotConnectedRecently Status = "NotConnectedRecently" + StatusNotSpecified Status = "NotSpecified" + StatusNotYetRegistered Status = "NotYetRegistered" + StatusValidationFailed Status = "ValidationFailed" + StatusValidationInProgress Status = "ValidationInProgress" + StatusValidationSuccess Status = "ValidationSuccess" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConnectedRecently), + string(StatusDeploymentFailed), + string(StatusDeploymentInProgress), + string(StatusDeploymentSuccess), + string(StatusDisconnected), + string(StatusError), + string(StatusNotConnectedRecently), + string(StatusNotSpecified), + string(StatusNotYetRegistered), + string(StatusValidationFailed), + string(StatusValidationInProgress), + string(StatusValidationSuccess), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "connectedrecently": StatusConnectedRecently, + "deploymentfailed": StatusDeploymentFailed, + "deploymentinprogress": StatusDeploymentInProgress, + "deploymentsuccess": StatusDeploymentSuccess, + "disconnected": StatusDisconnected, + "error": StatusError, + "notconnectedrecently": StatusNotConnectedRecently, + "notspecified": StatusNotSpecified, + "notyetregistered": StatusNotYetRegistered, + "validationfailed": StatusValidationFailed, + "validationinprogress": StatusValidationInProgress, + "validationsuccess": StatusValidationSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type WindowsServerSubscription string + +const ( + WindowsServerSubscriptionDisabled WindowsServerSubscription = "Disabled" + WindowsServerSubscriptionEnabled WindowsServerSubscription = "Enabled" +) + +func PossibleValuesForWindowsServerSubscription() []string { + return []string{ + string(WindowsServerSubscriptionDisabled), + string(WindowsServerSubscriptionEnabled), + } +} + +func (s *WindowsServerSubscription) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWindowsServerSubscription(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWindowsServerSubscription(input string) (*WindowsServerSubscription, error) { + vals := map[string]WindowsServerSubscription{ + "disabled": WindowsServerSubscriptionDisabled, + "enabled": WindowsServerSubscriptionEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WindowsServerSubscription(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster.go new file mode 100644 index 00000000000..9212b8c22b0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster.go @@ -0,0 +1,125 @@ +package clusters + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster_test.go new file mode 100644 index 00000000000..94a9e1ae438 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/id_cluster_test.go @@ -0,0 +1,282 @@ +package clusters + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/clusters/method_create.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_create.go new file mode 100644 index 00000000000..337ea36a215 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_create.go @@ -0,0 +1,58 @@ +package clusters + +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 CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// Create ... +func (c ClustersClient) Create(ctx context.Context, id ClusterId, input Cluster) (result CreateOperationResponse, 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 Cluster + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_delete.go new file mode 100644 index 00000000000..13e2610ffd6 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_delete.go @@ -0,0 +1,71 @@ +package clusters + +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 ClustersClient) Delete(ctx context.Context, id ClusterId) (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 ClustersClient) DeleteThenPoll(ctx context.Context, id ClusterId) 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/azurestackhci/2023-08-01-preview/clusters/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_get.go new file mode 100644 index 00000000000..73c53aa936b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_get.go @@ -0,0 +1,54 @@ +package clusters + +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 *Cluster +} + +// Get ... +func (c ClustersClient) Get(ctx context.Context, id ClusterId) (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 Cluster + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbyresourcegroup.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..ad6828ab30c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package clusters + +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 *[]Cluster +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +// ListByResourceGroup ... +func (c ClustersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.AzureStackHCI/clusters", 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 *[]Cluster `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 ClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ClusterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/clusters/method_listbysubscription.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbysubscription.go new file mode 100644 index 00000000000..6c551f757cc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_listbysubscription.go @@ -0,0 +1,92 @@ +package clusters + +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 *[]Cluster +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +// ListBySubscription ... +func (c ClustersClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.AzureStackHCI/clusters", 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 *[]Cluster `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 ClustersClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/clusters/method_update.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_update.go new file mode 100644 index 00000000000..80edce4b64f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/method_update.go @@ -0,0 +1,58 @@ +package clusters + +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 *Cluster +} + +// Update ... +func (c ClustersClient) Update(ctx context.Context, id ClusterId, input ClusterPatch) (result UpdateOperationResponse, 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 Cluster + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_cluster.go new file mode 100644 index 00000000000..d5b851dff01 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_cluster.go @@ -0,0 +1,20 @@ +package clusters + +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 Cluster struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `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/azurestackhci/2023-08-01-preview/clusters/model_clusterdesiredproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterdesiredproperties.go new file mode 100644 index 00000000000..3572f7c6d22 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterdesiredproperties.go @@ -0,0 +1,9 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterDesiredProperties struct { + DiagnosticLevel *DiagnosticLevel `json:"diagnosticLevel,omitempty"` + WindowsServerSubscription *WindowsServerSubscription `json:"windowsServerSubscription,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusternode.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusternode.go new file mode 100644 index 00000000000..ecd9442123c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusternode.go @@ -0,0 +1,40 @@ +package clusters + +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 ClusterNode struct { + CoreCount *float64 `json:"coreCount,omitempty"` + EhcResourceId *string `json:"ehcResourceId,omitempty"` + Id *float64 `json:"id,omitempty"` + LastLicensingTimestamp *string `json:"lastLicensingTimestamp,omitempty"` + Manufacturer *string `json:"manufacturer,omitempty"` + MemoryInGiB *float64 `json:"memoryInGiB,omitempty"` + Model *string `json:"model,omitempty"` + Name *string `json:"name,omitempty"` + NodeType *ClusterNodeType `json:"nodeType,omitempty"` + OemActivation *OemActivation `json:"oemActivation,omitempty"` + OsDisplayVersion *string `json:"osDisplayVersion,omitempty"` + OsName *string `json:"osName,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + SerialNumber *string `json:"serialNumber,omitempty"` + WindowsServerSubscription *WindowsServerSubscription `json:"windowsServerSubscription,omitempty"` +} + +func (o *ClusterNode) GetLastLicensingTimestampAsTime() (*time.Time, error) { + if o.LastLicensingTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastLicensingTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterNode) SetLastLicensingTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastLicensingTimestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatch.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatch.go new file mode 100644 index 00000000000..5f0c8dc17eb --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatch.go @@ -0,0 +1,14 @@ +package clusters + +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 ClusterPatch struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ClusterPatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatchproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatchproperties.go new file mode 100644 index 00000000000..04c86c75b34 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterpatchproperties.go @@ -0,0 +1,11 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPatchProperties struct { + AadClientId *string `json:"aadClientId,omitempty"` + AadTenantId *string `json:"aadTenantId,omitempty"` + CloudManagementEndpoint *string `json:"cloudManagementEndpoint,omitempty"` + DesiredProperties *ClusterDesiredProperties `json:"desiredProperties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterproperties.go new file mode 100644 index 00000000000..5f058ff9f5c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterproperties.go @@ -0,0 +1,69 @@ +package clusters + +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 ClusterProperties struct { + AadApplicationObjectId *string `json:"aadApplicationObjectId,omitempty"` + AadClientId *string `json:"aadClientId,omitempty"` + AadServicePrincipalObjectId *string `json:"aadServicePrincipalObjectId,omitempty"` + AadTenantId *string `json:"aadTenantId,omitempty"` + BillingModel *string `json:"billingModel,omitempty"` + CloudId *string `json:"cloudId,omitempty"` + CloudManagementEndpoint *string `json:"cloudManagementEndpoint,omitempty"` + ConnectivityStatus *ConnectivityStatus `json:"connectivityStatus,omitempty"` + DesiredProperties *ClusterDesiredProperties `json:"desiredProperties,omitempty"` + IsolatedVMAttestationConfiguration *IsolatedVMAttestationConfiguration `json:"isolatedVmAttestationConfiguration,omitempty"` + LastBillingTimestamp *string `json:"lastBillingTimestamp,omitempty"` + LastSyncTimestamp *string `json:"lastSyncTimestamp,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RegistrationTimestamp *string `json:"registrationTimestamp,omitempty"` + ReportedProperties *ClusterReportedProperties `json:"reportedProperties,omitempty"` + ResourceProviderObjectId *string `json:"resourceProviderObjectId,omitempty"` + ServiceEndpoint *string `json:"serviceEndpoint,omitempty"` + SoftwareAssuranceProperties *SoftwareAssuranceProperties `json:"softwareAssuranceProperties,omitempty"` + Status *Status `json:"status,omitempty"` + TrialDaysRemaining *float64 `json:"trialDaysRemaining,omitempty"` +} + +func (o *ClusterProperties) GetLastBillingTimestampAsTime() (*time.Time, error) { + if o.LastBillingTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastBillingTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetLastBillingTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastBillingTimestamp = &formatted +} + +func (o *ClusterProperties) GetLastSyncTimestampAsTime() (*time.Time, error) { + if o.LastSyncTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetLastSyncTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTimestamp = &formatted +} + +func (o *ClusterProperties) GetRegistrationTimestampAsTime() (*time.Time, error) { + if o.RegistrationTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegistrationTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetRegistrationTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegistrationTimestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterreportedproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterreportedproperties.go new file mode 100644 index 00000000000..732f0efd40a --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_clusterreportedproperties.go @@ -0,0 +1,36 @@ +package clusters + +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 ClusterReportedProperties struct { + ClusterId *string `json:"clusterId,omitempty"` + ClusterName *string `json:"clusterName,omitempty"` + ClusterType *ClusterNodeType `json:"clusterType,omitempty"` + ClusterVersion *string `json:"clusterVersion,omitempty"` + DiagnosticLevel *DiagnosticLevel `json:"diagnosticLevel,omitempty"` + ImdsAttestation *ImdsAttestation `json:"imdsAttestation,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + Manufacturer *string `json:"manufacturer,omitempty"` + Nodes *[]ClusterNode `json:"nodes,omitempty"` + OemActivation *OemActivation `json:"oemActivation,omitempty"` + SupportedCapabilities *[]string `json:"supportedCapabilities,omitempty"` +} + +func (o *ClusterReportedProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterReportedProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_isolatedvmattestationconfiguration.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_isolatedvmattestationconfiguration.go new file mode 100644 index 00000000000..e6fb467b2dc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_isolatedvmattestationconfiguration.go @@ -0,0 +1,10 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IsolatedVMAttestationConfiguration struct { + AttestationResourceId *string `json:"attestationResourceId,omitempty"` + AttestationServiceEndpoint *string `json:"attestationServiceEndpoint,omitempty"` + RelyingPartyServiceEndpoint *string `json:"relyingPartyServiceEndpoint,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_softwareassuranceproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_softwareassuranceproperties.go new file mode 100644 index 00000000000..5d2953809b5 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/model_softwareassuranceproperties.go @@ -0,0 +1,28 @@ +package clusters + +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 SoftwareAssuranceProperties struct { + LastUpdated *string `json:"lastUpdated,omitempty"` + SoftwareAssuranceIntent *SoftwareAssuranceIntent `json:"softwareAssuranceIntent,omitempty"` + SoftwareAssuranceStatus *SoftwareAssuranceStatus `json:"softwareAssuranceStatus,omitempty"` +} + +func (o *SoftwareAssuranceProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SoftwareAssuranceProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/clusters/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/predicates.go new file mode 100644 index 00000000000..cc13b7c6220 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/predicates.go @@ -0,0 +1,32 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ClusterOperationPredicate) Matches(input Cluster) 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/azurestackhci/2023-08-01-preview/clusters/version.go b/resource-manager/azurestackhci/2023-08-01-preview/clusters/version.go new file mode 100644 index 00000000000..7813dcbbff9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/clusters/version.go @@ -0,0 +1,12 @@ +package clusters + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/clusters/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/README.md b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/README.md new file mode 100644 index 00000000000..ea04727bcc8 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings` Documentation + +The `deploymentsettings` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/deploymentsettings" +``` + + +### Client Initialization + +```go +client := deploymentsettings.NewDeploymentSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := deploymentsettings.NewDeploymentSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "deploymentSettingValue") + +payload := deploymentsettings.DeploymentSetting{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentSettingsClient.Delete` + +```go +ctx := context.TODO() +id := deploymentsettings.NewDeploymentSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "deploymentSettingValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentSettingsClient.Get` + +```go +ctx := context.TODO() +id := deploymentsettings.NewDeploymentSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "deploymentSettingValue") + +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: `DeploymentSettingsClient.ListByClusters` + +```go +ctx := context.TODO() +id := deploymentsettings.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// alternatively `client.ListByClusters(ctx, id)` can be used to do batched pagination +items, err := client.ListByClustersComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/client.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/client.go new file mode 100644 index 00000000000..2d772172804 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/client.go @@ -0,0 +1,26 @@ +package deploymentsettings + +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 DeploymentSettingsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deploymentsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentSettingsClient: %+v", err) + } + + return &DeploymentSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/constants.go new file mode 100644 index 00000000000..a572b56aa22 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/constants.go @@ -0,0 +1,110 @@ +package deploymentsettings + +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 DeploymentMode string + +const ( + DeploymentModeDeploy DeploymentMode = "Deploy" + DeploymentModeValidate DeploymentMode = "Validate" +) + +func PossibleValuesForDeploymentMode() []string { + return []string{ + string(DeploymentModeDeploy), + string(DeploymentModeValidate), + } +} + +func (s *DeploymentMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentMode(input string) (*DeploymentMode, error) { + vals := map[string]DeploymentMode{ + "deploy": DeploymentModeDeploy, + "validate": DeploymentModeValidate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentMode(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateProvisioning), + 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, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "provisioning": ProvisioningStateProvisioning, + "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/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster.go new file mode 100644 index 00000000000..dc92e4f4cc4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster.go @@ -0,0 +1,125 @@ +package deploymentsettings + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster_test.go new file mode 100644 index 00000000000..8fff3ee0215 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_cluster_test.go @@ -0,0 +1,282 @@ +package deploymentsettings + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting.go new file mode 100644 index 00000000000..32dad80bc02 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting.go @@ -0,0 +1,134 @@ +package deploymentsettings + +import ( + "fmt" + "strings" + + "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 = &DeploymentSettingId{} + +// DeploymentSettingId is a struct representing the Resource ID for a Deployment Setting +type DeploymentSettingId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + DeploymentSettingName string +} + +// NewDeploymentSettingID returns a new DeploymentSettingId struct +func NewDeploymentSettingID(subscriptionId string, resourceGroupName string, clusterName string, deploymentSettingName string) DeploymentSettingId { + return DeploymentSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + DeploymentSettingName: deploymentSettingName, + } +} + +// ParseDeploymentSettingID parses 'input' into a DeploymentSettingId +func ParseDeploymentSettingID(input string) (*DeploymentSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentSettingIDInsensitively parses 'input' case-insensitively into a DeploymentSettingId +// note: this method should only be used for API response data and not user input +func ParseDeploymentSettingIDInsensitively(input string) (*DeploymentSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentSettingId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.DeploymentSettingName, ok = input.Parsed["deploymentSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentSettingName", input) + } + + return nil +} + +// ValidateDeploymentSettingID checks that 'input' can be parsed as a Deployment Setting ID +func ValidateDeploymentSettingID(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 := ParseDeploymentSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment Setting ID +func (id DeploymentSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/deploymentSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.DeploymentSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment Setting ID +func (id DeploymentSettingId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticDeploymentSettings", "deploymentSettings", "deploymentSettings"), + resourceids.UserSpecifiedSegment("deploymentSettingName", "deploymentSettingValue"), + } +} + +// String returns a human-readable description of this Deployment Setting ID +func (id DeploymentSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Deployment Setting Name: %q", id.DeploymentSettingName), + } + return fmt.Sprintf("Deployment Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting_test.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting_test.go new file mode 100644 index 00000000000..1901472bcd4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/id_deploymentsetting_test.go @@ -0,0 +1,327 @@ +package deploymentsettings + +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 = &DeploymentSettingId{} + +func TestNewDeploymentSettingID(t *testing.T) { + id := NewDeploymentSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "deploymentSettingValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.DeploymentSettingName != "deploymentSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentSettingName'", id.DeploymentSettingName, "deploymentSettingValue") + } +} + +func TestFormatDeploymentSettingID(t *testing.T) { + actual := NewDeploymentSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "deploymentSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings/deploymentSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings/deploymentSettingValue", + Expected: &DeploymentSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + DeploymentSettingName: "deploymentSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings/deploymentSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentSettingID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.DeploymentSettingName != v.Expected.DeploymentSettingName { + t.Fatalf("Expected %q but got %q for DeploymentSettingName", v.Expected.DeploymentSettingName, actual.DeploymentSettingName) + } + + } +} + +func TestParseDeploymentSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/dEpLoYmEnTsEtTiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings/deploymentSettingValue", + Expected: &DeploymentSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + DeploymentSettingName: "deploymentSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/deploymentSettings/deploymentSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/dEpLoYmEnTsEtTiNgS/dEpLoYmEnTsEtTiNgVaLuE", + Expected: &DeploymentSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + DeploymentSettingName: "dEpLoYmEnTsEtTiNgVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/dEpLoYmEnTsEtTiNgS/dEpLoYmEnTsEtTiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentSettingIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.DeploymentSettingName != v.Expected.DeploymentSettingName { + t.Fatalf("Expected %q but got %q for DeploymentSettingName", v.Expected.DeploymentSettingName, actual.DeploymentSettingName) + } + + } +} + +func TestSegmentsForDeploymentSettingId(t *testing.T) { + segments := DeploymentSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentSettingId 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/azurestackhci/2023-08-01-preview/deploymentsettings/method_createorupdate.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_createorupdate.go new file mode 100644 index 00000000000..1338dda3db5 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_createorupdate.go @@ -0,0 +1,75 @@ +package deploymentsettings + +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 *DeploymentSetting +} + +// CreateOrUpdate ... +func (c DeploymentSettingsClient) CreateOrUpdate(ctx context.Context, id DeploymentSettingId, input DeploymentSetting) (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 DeploymentSettingsClient) CreateOrUpdateThenPoll(ctx context.Context, id DeploymentSettingId, input DeploymentSetting) 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/azurestackhci/2023-08-01-preview/deploymentsettings/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_delete.go new file mode 100644 index 00000000000..89e29cd7e90 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_delete.go @@ -0,0 +1,70 @@ +package deploymentsettings + +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 DeploymentSettingsClient) Delete(ctx context.Context, id DeploymentSettingId) (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 DeploymentSettingsClient) DeleteThenPoll(ctx context.Context, id DeploymentSettingId) 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/azurestackhci/2023-08-01-preview/deploymentsettings/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_get.go new file mode 100644 index 00000000000..c87af231c1b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_get.go @@ -0,0 +1,54 @@ +package deploymentsettings + +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 *DeploymentSetting +} + +// Get ... +func (c DeploymentSettingsClient) Get(ctx context.Context, id DeploymentSettingId) (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 DeploymentSetting + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_listbyclusters.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_listbyclusters.go new file mode 100644 index 00000000000..124423cbf9a --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/method_listbyclusters.go @@ -0,0 +1,91 @@ +package deploymentsettings + +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 ListByClustersOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentSetting +} + +type ListByClustersCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentSetting +} + +// ListByClusters ... +func (c DeploymentSettingsClient) ListByClusters(ctx context.Context, id ClusterId) (result ListByClustersOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/deploymentSettings", 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 *[]DeploymentSetting `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByClustersComplete retrieves all the results into a single object +func (c DeploymentSettingsClient) ListByClustersComplete(ctx context.Context, id ClusterId) (ListByClustersCompleteResult, error) { + return c.ListByClustersCompleteMatchingPredicate(ctx, id, DeploymentSettingOperationPredicate{}) +} + +// ListByClustersCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentSettingsClient) ListByClustersCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate DeploymentSettingOperationPredicate) (result ListByClustersCompleteResult, err error) { + items := make([]DeploymentSetting, 0) + + resp, err := c.ListByClusters(ctx, id) + if err != nil { + 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 = ListByClustersCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_adapterpropertyoverrides.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_adapterpropertyoverrides.go new file mode 100644 index 00000000000..57b6e9dc686 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_adapterpropertyoverrides.go @@ -0,0 +1,10 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdapterPropertyOverrides struct { + JumboPacket *string `json:"jumboPacket,omitempty"` + NetworkDirect *string `json:"networkDirect,omitempty"` + NetworkDirectTechnology *string `json:"networkDirectTechnology,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_cluster.go new file mode 100644 index 00000000000..19ca2741a93 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_cluster.go @@ -0,0 +1,12 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Cluster struct { + AzureServiceEndpoint *string `json:"azureServiceEndpoint,omitempty"` + CloudAccountName *string `json:"cloudAccountName,omitempty"` + Name *string `json:"name,omitempty"` + WitnessPath *string `json:"witnessPath,omitempty"` + WitnessType *string `json:"witnessType,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentconfiguration.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentconfiguration.go new file mode 100644 index 00000000000..2725ef47249 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentconfiguration.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentConfiguration struct { + ScaleUnits []ScaleUnits `json:"scaleUnits"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentdata.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentdata.go new file mode 100644 index 00000000000..fa9cc4addd2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentdata.go @@ -0,0 +1,19 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentData struct { + AdouPath *string `json:"adouPath,omitempty"` + Cluster *Cluster `json:"cluster,omitempty"` + DomainFqdn *string `json:"domainFqdn,omitempty"` + HostNetwork *HostNetwork `json:"hostNetwork,omitempty"` + InfrastructureNetwork *[]InfrastructureNetwork `json:"infrastructureNetwork,omitempty"` + NamingPrefix *string `json:"namingPrefix,omitempty"` + Observability *Observability `json:"observability,omitempty"` + OptionalServices *OptionalServices `json:"optionalServices,omitempty"` + PhysicalNodes *[]PhysicalNodes `json:"physicalNodes,omitempty"` + SecretsLocation *string `json:"secretsLocation,omitempty"` + SecuritySettings *SecuritySettings `json:"securitySettings,omitempty"` + Storage *Storage `json:"storage,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsetting.go new file mode 100644 index 00000000000..9f687fa2dfd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsetting.go @@ -0,0 +1,16 @@ +package deploymentsettings + +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 DeploymentSetting struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeploymentSettingsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsettingsproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsettingsproperties.go new file mode 100644 index 00000000000..cd74013705d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentsettingsproperties.go @@ -0,0 +1,12 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentSettingsProperties struct { + ArcNodeResourceIds []string `json:"arcNodeResourceIds"` + DeploymentConfiguration DeploymentConfiguration `json:"deploymentConfiguration"` + DeploymentMode DeploymentMode `json:"deploymentMode"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ReportedProperties *ReportedProperties `json:"reportedProperties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentstatus.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentstatus.go new file mode 100644 index 00000000000..5a043950d68 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_deploymentstatus.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentStatus struct { + Status *string `json:"status,omitempty"` + Steps *[]Step `json:"steps,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_hostnetwork.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_hostnetwork.go new file mode 100644 index 00000000000..8bd87a42076 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_hostnetwork.go @@ -0,0 +1,11 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostNetwork struct { + EnableStorageAutoIP *bool `json:"enableStorageAutoIp,omitempty"` + Intents *[]Intents `json:"intents,omitempty"` + StorageConnectivitySwitchless *bool `json:"storageConnectivitySwitchless,omitempty"` + StorageNetworks *[]StorageNetworks `json:"storageNetworks,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_infrastructurenetwork.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_infrastructurenetwork.go new file mode 100644 index 00000000000..b19bbf287a4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_infrastructurenetwork.go @@ -0,0 +1,12 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InfrastructureNetwork struct { + DnsServers *[]string `json:"dnsServers,omitempty"` + Gateway *string `json:"gateway,omitempty"` + IPPools *[]IPPools `json:"ipPools,omitempty"` + SubnetMask *string `json:"subnetMask,omitempty"` + UseDhcp *bool `json:"useDhcp,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_intents.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_intents.go new file mode 100644 index 00000000000..6e43eb8be88 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_intents.go @@ -0,0 +1,16 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Intents struct { + Adapter *[]string `json:"adapter,omitempty"` + AdapterPropertyOverrides *AdapterPropertyOverrides `json:"adapterPropertyOverrides,omitempty"` + Name *string `json:"name,omitempty"` + OverrideAdapterProperty *bool `json:"overrideAdapterProperty,omitempty"` + OverrideQosPolicy *bool `json:"overrideQosPolicy,omitempty"` + OverrideVirtualSwitchConfiguration *bool `json:"overrideVirtualSwitchConfiguration,omitempty"` + QosPolicyOverrides *QosPolicyOverrides `json:"qosPolicyOverrides,omitempty"` + TrafficType *[]string `json:"trafficType,omitempty"` + VirtualSwitchConfigurationOverrides *VirtualSwitchConfigurationOverrides `json:"virtualSwitchConfigurationOverrides,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_ippools.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_ippools.go new file mode 100644 index 00000000000..9b95a1dce7b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_ippools.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPPools struct { + EndingAddress *string `json:"endingAddress,omitempty"` + StartingAddress *string `json:"startingAddress,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_observability.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_observability.go new file mode 100644 index 00000000000..350c5bb85fd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_observability.go @@ -0,0 +1,10 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Observability struct { + EpisodicDataUpload *bool `json:"episodicDataUpload,omitempty"` + EuLocation *bool `json:"euLocation,omitempty"` + StreamingDataClient *bool `json:"streamingDataClient,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_optionalservices.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_optionalservices.go new file mode 100644 index 00000000000..9176350170c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_optionalservices.go @@ -0,0 +1,8 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OptionalServices struct { + CustomLocation *string `json:"customLocation,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_physicalnodes.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_physicalnodes.go new file mode 100644 index 00000000000..75473c3a914 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_physicalnodes.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PhysicalNodes struct { + IPv4Address *string `json:"ipv4Address,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_qospolicyoverrides.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_qospolicyoverrides.go new file mode 100644 index 00000000000..c523de45ee6 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_qospolicyoverrides.go @@ -0,0 +1,10 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QosPolicyOverrides struct { + BandwidthPercentageSMB *string `json:"bandwidthPercentage_SMB,omitempty"` + PriorityValue8021ActionCluster *string `json:"priorityValue8021Action_Cluster,omitempty"` + PriorityValue8021ActionSMB *string `json:"priorityValue8021Action_SMB,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_reportedproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_reportedproperties.go new file mode 100644 index 00000000000..959d1a3c5d2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_reportedproperties.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportedProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + ValidationStatus *ValidationStatus `json:"validationStatus,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_scaleunits.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_scaleunits.go new file mode 100644 index 00000000000..196b7cfe805 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_scaleunits.go @@ -0,0 +1,8 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleUnits struct { + DeploymentData DeploymentData `json:"deploymentData"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_securitysettings.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_securitysettings.go new file mode 100644 index 00000000000..e4927952af6 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_securitysettings.go @@ -0,0 +1,17 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecuritySettings struct { + BitlockerBootVolume *bool `json:"bitlockerBootVolume,omitempty"` + BitlockerDataVolumes *bool `json:"bitlockerDataVolumes,omitempty"` + CredentialGuardEnforced *bool `json:"credentialGuardEnforced,omitempty"` + DriftControlEnforced *bool `json:"driftControlEnforced,omitempty"` + DrtmProtection *bool `json:"drtmProtection,omitempty"` + HvciProtection *bool `json:"hvciProtection,omitempty"` + SideChannelMitigationEnforced *bool `json:"sideChannelMitigationEnforced,omitempty"` + SmbClusterEncryption *bool `json:"smbClusterEncryption,omitempty"` + SmbSigningEnforced *bool `json:"smbSigningEnforced,omitempty"` + WdacEnforced *bool `json:"wdacEnforced,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_step.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_step.go new file mode 100644 index 00000000000..25d97dccefe --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_step.go @@ -0,0 +1,15 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Step struct { + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + Exception *[]string `json:"exception,omitempty"` + FullStepIndex *string `json:"fullStepIndex,omitempty"` + Name *string `json:"name,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *string `json:"status,omitempty"` + Steps *[]Step `json:"steps,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storage.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storage.go new file mode 100644 index 00000000000..75bcd02c64f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storage.go @@ -0,0 +1,8 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Storage struct { + ConfigurationMode *string `json:"configurationMode,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storagenetworks.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storagenetworks.go new file mode 100644 index 00000000000..1ac4234d92c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_storagenetworks.go @@ -0,0 +1,10 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageNetworks struct { + Name *string `json:"name,omitempty"` + NetworkAdapterName *string `json:"networkAdapterName,omitempty"` + VlanId *string `json:"vlanId,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_validationstatus.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_validationstatus.go new file mode 100644 index 00000000000..cf0ea1c6b80 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_validationstatus.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidationStatus struct { + Status *string `json:"status,omitempty"` + Steps *[]Step `json:"steps,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_virtualswitchconfigurationoverrides.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_virtualswitchconfigurationoverrides.go new file mode 100644 index 00000000000..11d87905241 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/model_virtualswitchconfigurationoverrides.go @@ -0,0 +1,9 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualSwitchConfigurationOverrides struct { + EnableIov *string `json:"enableIov,omitempty"` + LoadBalancingAlgorithm *string `json:"loadBalancingAlgorithm,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/predicates.go new file mode 100644 index 00000000000..5b37f41b7b5 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/predicates.go @@ -0,0 +1,27 @@ +package deploymentsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentSettingOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeploymentSettingOperationPredicate) Matches(input DeploymentSetting) 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/azurestackhci/2023-08-01-preview/deploymentsettings/version.go b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/version.go new file mode 100644 index 00000000000..a2310bb17d2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/deploymentsettings/version.go @@ -0,0 +1,12 @@ +package deploymentsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deploymentsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/README.md b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/README.md new file mode 100644 index 00000000000..44beb4189bd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/edgedevices` Documentation + +The `edgedevices` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/edgedevices" +``` + + +### Client Initialization + +```go +client := edgedevices.NewEdgeDevicesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EdgeDevicesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := edgedevices.NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue") + +payload := edgedevices.EdgeDevice{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EdgeDevicesClient.Delete` + +```go +ctx := context.TODO() +id := edgedevices.NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EdgeDevicesClient.Get` + +```go +ctx := context.TODO() +id := edgedevices.NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue") + +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: `EdgeDevicesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// 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: `EdgeDevicesClient.Validate` + +```go +ctx := context.TODO() +id := edgedevices.NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue") + +payload := edgedevices.ValidateRequest{ + // ... +} + + +if err := client.ValidateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/client.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/client.go new file mode 100644 index 00000000000..629b201ceec --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/client.go @@ -0,0 +1,26 @@ +package edgedevices + +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 EdgeDevicesClient struct { + Client *resourcemanager.Client +} + +func NewEdgeDevicesClientWithBaseURI(sdkApi sdkEnv.Api) (*EdgeDevicesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "edgedevices", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EdgeDevicesClient: %+v", err) + } + + return &EdgeDevicesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/constants.go new file mode 100644 index 00000000000..0a9012702bd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/constants.go @@ -0,0 +1,69 @@ +package edgedevices + +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" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateProvisioning), + 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, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "provisioning": ProvisioningStateProvisioning, + "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/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice.go new file mode 100644 index 00000000000..160f17394fd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice.go @@ -0,0 +1,115 @@ +package edgedevices + +import ( + "fmt" + "strings" + + "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 = &ScopedEdgeDeviceId{} + +// ScopedEdgeDeviceId is a struct representing the Resource ID for a Scoped Edge Device +type ScopedEdgeDeviceId struct { + ResourceUri string + EdgeDeviceName string +} + +// NewScopedEdgeDeviceID returns a new ScopedEdgeDeviceId struct +func NewScopedEdgeDeviceID(resourceUri string, edgeDeviceName string) ScopedEdgeDeviceId { + return ScopedEdgeDeviceId{ + ResourceUri: resourceUri, + EdgeDeviceName: edgeDeviceName, + } +} + +// ParseScopedEdgeDeviceID parses 'input' into a ScopedEdgeDeviceId +func ParseScopedEdgeDeviceID(input string) (*ScopedEdgeDeviceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedEdgeDeviceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedEdgeDeviceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedEdgeDeviceIDInsensitively parses 'input' case-insensitively into a ScopedEdgeDeviceId +// note: this method should only be used for API response data and not user input +func ParseScopedEdgeDeviceIDInsensitively(input string) (*ScopedEdgeDeviceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedEdgeDeviceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedEdgeDeviceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedEdgeDeviceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ResourceUri, ok = input.Parsed["resourceUri"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceUri", input) + } + + if id.EdgeDeviceName, ok = input.Parsed["edgeDeviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "edgeDeviceName", input) + } + + return nil +} + +// ValidateScopedEdgeDeviceID checks that 'input' can be parsed as a Scoped Edge Device ID +func ValidateScopedEdgeDeviceID(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 := ParseScopedEdgeDeviceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Edge Device ID +func (id ScopedEdgeDeviceId) ID() string { + fmtString := "/%s/providers/Microsoft.AzureStackHCI/edgeDevices/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.ResourceUri, "/"), id.EdgeDeviceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Edge Device ID +func (id ScopedEdgeDeviceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("resourceUri", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticEdgeDevices", "edgeDevices", "edgeDevices"), + resourceids.UserSpecifiedSegment("edgeDeviceName", "edgeDeviceValue"), + } +} + +// String returns a human-readable description of this Scoped Edge Device ID +func (id ScopedEdgeDeviceId) String() string { + components := []string{ + fmt.Sprintf("Resource Uri: %q", id.ResourceUri), + fmt.Sprintf("Edge Device Name: %q", id.EdgeDeviceName), + } + return fmt.Sprintf("Scoped Edge Device (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice_test.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice_test.go new file mode 100644 index 00000000000..92654604c47 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/id_scopededgedevice_test.go @@ -0,0 +1,222 @@ +package edgedevices + +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 = &ScopedEdgeDeviceId{} + +func TestNewScopedEdgeDeviceID(t *testing.T) { + id := NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue") + + if id.ResourceUri != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceUri'", id.ResourceUri, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.EdgeDeviceName != "edgeDeviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'EdgeDeviceName'", id.EdgeDeviceName, "edgeDeviceValue") + } +} + +func TestFormatScopedEdgeDeviceID(t *testing.T) { + actual := NewScopedEdgeDeviceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "edgeDeviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices/edgeDeviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedEdgeDeviceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedEdgeDeviceId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices/edgeDeviceValue", + Expected: &ScopedEdgeDeviceId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + EdgeDeviceName: "edgeDeviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices/edgeDeviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedEdgeDeviceID(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.ResourceUri != v.Expected.ResourceUri { + t.Fatalf("Expected %q but got %q for ResourceUri", v.Expected.ResourceUri, actual.ResourceUri) + } + + if actual.EdgeDeviceName != v.Expected.EdgeDeviceName { + t.Fatalf("Expected %q but got %q for EdgeDeviceName", v.Expected.EdgeDeviceName, actual.EdgeDeviceName) + } + + } +} + +func TestParseScopedEdgeDeviceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedEdgeDeviceId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/eDgEdEvIcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices/edgeDeviceValue", + Expected: &ScopedEdgeDeviceId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + EdgeDeviceName: "edgeDeviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.AzureStackHCI/edgeDevices/edgeDeviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/eDgEdEvIcEs/eDgEdEvIcEvAlUe", + Expected: &ScopedEdgeDeviceId{ + ResourceUri: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + EdgeDeviceName: "eDgEdEvIcEvAlUe", + }, + }, + { + // 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.aZuReStAcKhCi/eDgEdEvIcEs/eDgEdEvIcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedEdgeDeviceIDInsensitively(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.ResourceUri != v.Expected.ResourceUri { + t.Fatalf("Expected %q but got %q for ResourceUri", v.Expected.ResourceUri, actual.ResourceUri) + } + + if actual.EdgeDeviceName != v.Expected.EdgeDeviceName { + t.Fatalf("Expected %q but got %q for EdgeDeviceName", v.Expected.EdgeDeviceName, actual.EdgeDeviceName) + } + + } +} + +func TestSegmentsForScopedEdgeDeviceId(t *testing.T) { + segments := ScopedEdgeDeviceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedEdgeDeviceId 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/azurestackhci/2023-08-01-preview/edgedevices/method_createorupdate.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_createorupdate.go new file mode 100644 index 00000000000..23058042e19 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_createorupdate.go @@ -0,0 +1,75 @@ +package edgedevices + +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 *EdgeDevice +} + +// CreateOrUpdate ... +func (c EdgeDevicesClient) CreateOrUpdate(ctx context.Context, id ScopedEdgeDeviceId, input EdgeDevice) (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 EdgeDevicesClient) CreateOrUpdateThenPoll(ctx context.Context, id ScopedEdgeDeviceId, input EdgeDevice) 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/azurestackhci/2023-08-01-preview/edgedevices/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_delete.go new file mode 100644 index 00000000000..22cea7a6138 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_delete.go @@ -0,0 +1,71 @@ +package edgedevices + +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 EdgeDevicesClient) Delete(ctx context.Context, id ScopedEdgeDeviceId) (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 EdgeDevicesClient) DeleteThenPoll(ctx context.Context, id ScopedEdgeDeviceId) 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/azurestackhci/2023-08-01-preview/edgedevices/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_get.go new file mode 100644 index 00000000000..b689f330ce3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_get.go @@ -0,0 +1,54 @@ +package edgedevices + +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 *EdgeDevice +} + +// Get ... +func (c EdgeDevicesClient) Get(ctx context.Context, id ScopedEdgeDeviceId) (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 EdgeDevice + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_list.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_list.go new file mode 100644 index 00000000000..8d62a20d743 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_list.go @@ -0,0 +1,92 @@ +package edgedevices + +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 *[]EdgeDevice +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EdgeDevice +} + +// List ... +func (c EdgeDevicesClient) List(ctx context.Context, id commonids.ScopeId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.AzureStackHCI/edgeDevices", 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 *[]EdgeDevice `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 EdgeDevicesClient) ListComplete(ctx context.Context, id commonids.ScopeId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, EdgeDeviceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EdgeDevicesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate EdgeDeviceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EdgeDevice, 0) + + resp, err := c.List(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/edgedevices/method_validate.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_validate.go new file mode 100644 index 00000000000..d27edbf6a8e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/method_validate.go @@ -0,0 +1,75 @@ +package edgedevices + +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 ValidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ValidateResponse +} + +// Validate ... +func (c EdgeDevicesClient) Validate(ctx context.Context, id ScopedEdgeDeviceId, input ValidateRequest) (result ValidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validate", 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 +} + +// ValidateThenPoll performs Validate then polls until it's completed +func (c EdgeDevicesClient) ValidateThenPoll(ctx context.Context, id ScopedEdgeDeviceId, input ValidateRequest) error { + result, err := c.Validate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Validate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Validate: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_deviceconfiguration.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_deviceconfiguration.go new file mode 100644 index 00000000000..c22933f040d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_deviceconfiguration.go @@ -0,0 +1,9 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeviceConfiguration struct { + DeviceMetadata *string `json:"deviceMetadata,omitempty"` + NicDetails []NicDetail `json:"nicDetails"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedevice.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedevice.go new file mode 100644 index 00000000000..02a3e9f4e27 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedevice.go @@ -0,0 +1,16 @@ +package edgedevices + +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 EdgeDevice struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EdgeDeviceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedeviceproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedeviceproperties.go new file mode 100644 index 00000000000..09b93829e17 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_edgedeviceproperties.go @@ -0,0 +1,9 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EdgeDeviceProperties struct { + DeviceConfiguration DeviceConfiguration `json:"deviceConfiguration"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_nicdetail.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_nicdetail.go new file mode 100644 index 00000000000..dfa392749d0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_nicdetail.go @@ -0,0 +1,16 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NicDetail struct { + AdapterName string `json:"adapterName"` + ComponentId *string `json:"componentId,omitempty"` + DefaultGateway *string `json:"defaultGateway,omitempty"` + DefaultIsolationId *string `json:"defaultIsolationId,omitempty"` + DnsServers *[]string `json:"dnsServers,omitempty"` + DriverVersion *string `json:"driverVersion,omitempty"` + IP4Address *string `json:"ip4Address,omitempty"` + InterfaceDescription *string `json:"interfaceDescription,omitempty"` + SubnetMask *string `json:"subnetMask,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validaterequest.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validaterequest.go new file mode 100644 index 00000000000..3bbd45293f3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validaterequest.go @@ -0,0 +1,9 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateRequest struct { + AdditionalInfo *string `json:"additionalInfo,omitempty"` + EdgeDeviceIds []string `json:"edgeDeviceIds"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validateresponse.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validateresponse.go new file mode 100644 index 00000000000..d9d470839e1 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/model_validateresponse.go @@ -0,0 +1,8 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateResponse struct { + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/predicates.go new file mode 100644 index 00000000000..662e3d34a4d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/predicates.go @@ -0,0 +1,27 @@ +package edgedevices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EdgeDeviceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EdgeDeviceOperationPredicate) Matches(input EdgeDevice) 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/azurestackhci/2023-08-01-preview/edgedevices/version.go b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/version.go new file mode 100644 index 00000000000..25929b787b1 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/edgedevices/version.go @@ -0,0 +1,12 @@ +package edgedevices + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/edgedevices/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/README.md b/resource-manager/azurestackhci/2023-08-01-preview/extensions/README.md new file mode 100644 index 00000000000..b9932aca7f4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/extensions` Documentation + +The `extensions` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/extensions" +``` + + +### Client Initialization + +```go +client := extensions.NewExtensionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ExtensionsClient.Create` + +```go +ctx := context.TODO() +id := extensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + +payload := extensions.Extension{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ExtensionsClient.Delete` + +```go +ctx := context.TODO() +id := extensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ExtensionsClient.Get` + +```go +ctx := context.TODO() +id := extensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + +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: `ExtensionsClient.ListByArcSetting` + +```go +ctx := context.TODO() +id := extensions.NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + +// alternatively `client.ListByArcSetting(ctx, id)` can be used to do batched pagination +items, err := client.ListByArcSettingComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ExtensionsClient.Update` + +```go +ctx := context.TODO() +id := extensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + +payload := extensions.ExtensionPatch{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ExtensionsClient.Upgrade` + +```go +ctx := context.TODO() +id := extensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + +payload := extensions.ExtensionUpgradeParameters{ + // ... +} + + +if err := client.UpgradeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/client.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/client.go new file mode 100644 index 00000000000..44725ac0e84 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/client.go @@ -0,0 +1,26 @@ +package extensions + +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 ExtensionsClient struct { + Client *resourcemanager.Client +} + +func NewExtensionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ExtensionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "extensions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ExtensionsClient: %+v", err) + } + + return &ExtensionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/constants.go new file mode 100644 index 00000000000..638dc8a39de --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/constants.go @@ -0,0 +1,356 @@ +package extensions + +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 ExtensionAggregateState string + +const ( + ExtensionAggregateStateAccepted ExtensionAggregateState = "Accepted" + ExtensionAggregateStateCanceled ExtensionAggregateState = "Canceled" + ExtensionAggregateStateConnected ExtensionAggregateState = "Connected" + ExtensionAggregateStateCreating ExtensionAggregateState = "Creating" + ExtensionAggregateStateDeleted ExtensionAggregateState = "Deleted" + ExtensionAggregateStateDeleting ExtensionAggregateState = "Deleting" + ExtensionAggregateStateDisconnected ExtensionAggregateState = "Disconnected" + ExtensionAggregateStateError ExtensionAggregateState = "Error" + ExtensionAggregateStateFailed ExtensionAggregateState = "Failed" + ExtensionAggregateStateInProgress ExtensionAggregateState = "InProgress" + ExtensionAggregateStateMoving ExtensionAggregateState = "Moving" + ExtensionAggregateStateNotSpecified ExtensionAggregateState = "NotSpecified" + ExtensionAggregateStatePartiallyConnected ExtensionAggregateState = "PartiallyConnected" + ExtensionAggregateStatePartiallySucceeded ExtensionAggregateState = "PartiallySucceeded" + ExtensionAggregateStateProvisioning ExtensionAggregateState = "Provisioning" + ExtensionAggregateStateSucceeded ExtensionAggregateState = "Succeeded" + ExtensionAggregateStateUpdating ExtensionAggregateState = "Updating" + ExtensionAggregateStateUpgradeFailedRollbackSucceeded ExtensionAggregateState = "UpgradeFailedRollbackSucceeded" +) + +func PossibleValuesForExtensionAggregateState() []string { + return []string{ + string(ExtensionAggregateStateAccepted), + string(ExtensionAggregateStateCanceled), + string(ExtensionAggregateStateConnected), + string(ExtensionAggregateStateCreating), + string(ExtensionAggregateStateDeleted), + string(ExtensionAggregateStateDeleting), + string(ExtensionAggregateStateDisconnected), + string(ExtensionAggregateStateError), + string(ExtensionAggregateStateFailed), + string(ExtensionAggregateStateInProgress), + string(ExtensionAggregateStateMoving), + string(ExtensionAggregateStateNotSpecified), + string(ExtensionAggregateStatePartiallyConnected), + string(ExtensionAggregateStatePartiallySucceeded), + string(ExtensionAggregateStateProvisioning), + string(ExtensionAggregateStateSucceeded), + string(ExtensionAggregateStateUpdating), + string(ExtensionAggregateStateUpgradeFailedRollbackSucceeded), + } +} + +func (s *ExtensionAggregateState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtensionAggregateState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtensionAggregateState(input string) (*ExtensionAggregateState, error) { + vals := map[string]ExtensionAggregateState{ + "accepted": ExtensionAggregateStateAccepted, + "canceled": ExtensionAggregateStateCanceled, + "connected": ExtensionAggregateStateConnected, + "creating": ExtensionAggregateStateCreating, + "deleted": ExtensionAggregateStateDeleted, + "deleting": ExtensionAggregateStateDeleting, + "disconnected": ExtensionAggregateStateDisconnected, + "error": ExtensionAggregateStateError, + "failed": ExtensionAggregateStateFailed, + "inprogress": ExtensionAggregateStateInProgress, + "moving": ExtensionAggregateStateMoving, + "notspecified": ExtensionAggregateStateNotSpecified, + "partiallyconnected": ExtensionAggregateStatePartiallyConnected, + "partiallysucceeded": ExtensionAggregateStatePartiallySucceeded, + "provisioning": ExtensionAggregateStateProvisioning, + "succeeded": ExtensionAggregateStateSucceeded, + "updating": ExtensionAggregateStateUpdating, + "upgradefailedrollbacksucceeded": ExtensionAggregateStateUpgradeFailedRollbackSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtensionAggregateState(input) + return &out, nil +} + +type ExtensionManagedBy string + +const ( + ExtensionManagedByAzure ExtensionManagedBy = "Azure" + ExtensionManagedByUser ExtensionManagedBy = "User" +) + +func PossibleValuesForExtensionManagedBy() []string { + return []string{ + string(ExtensionManagedByAzure), + string(ExtensionManagedByUser), + } +} + +func (s *ExtensionManagedBy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtensionManagedBy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtensionManagedBy(input string) (*ExtensionManagedBy, error) { + vals := map[string]ExtensionManagedBy{ + "azure": ExtensionManagedByAzure, + "user": ExtensionManagedByUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtensionManagedBy(input) + return &out, nil +} + +type NodeExtensionState string + +const ( + NodeExtensionStateAccepted NodeExtensionState = "Accepted" + NodeExtensionStateCanceled NodeExtensionState = "Canceled" + NodeExtensionStateConnected NodeExtensionState = "Connected" + NodeExtensionStateCreating NodeExtensionState = "Creating" + NodeExtensionStateDeleted NodeExtensionState = "Deleted" + NodeExtensionStateDeleting NodeExtensionState = "Deleting" + NodeExtensionStateDisconnected NodeExtensionState = "Disconnected" + NodeExtensionStateError NodeExtensionState = "Error" + NodeExtensionStateFailed NodeExtensionState = "Failed" + NodeExtensionStateInProgress NodeExtensionState = "InProgress" + NodeExtensionStateMoving NodeExtensionState = "Moving" + NodeExtensionStateNotSpecified NodeExtensionState = "NotSpecified" + NodeExtensionStatePartiallyConnected NodeExtensionState = "PartiallyConnected" + NodeExtensionStatePartiallySucceeded NodeExtensionState = "PartiallySucceeded" + NodeExtensionStateProvisioning NodeExtensionState = "Provisioning" + NodeExtensionStateSucceeded NodeExtensionState = "Succeeded" + NodeExtensionStateUpdating NodeExtensionState = "Updating" +) + +func PossibleValuesForNodeExtensionState() []string { + return []string{ + string(NodeExtensionStateAccepted), + string(NodeExtensionStateCanceled), + string(NodeExtensionStateConnected), + string(NodeExtensionStateCreating), + string(NodeExtensionStateDeleted), + string(NodeExtensionStateDeleting), + string(NodeExtensionStateDisconnected), + string(NodeExtensionStateError), + string(NodeExtensionStateFailed), + string(NodeExtensionStateInProgress), + string(NodeExtensionStateMoving), + string(NodeExtensionStateNotSpecified), + string(NodeExtensionStatePartiallyConnected), + string(NodeExtensionStatePartiallySucceeded), + string(NodeExtensionStateProvisioning), + string(NodeExtensionStateSucceeded), + string(NodeExtensionStateUpdating), + } +} + +func (s *NodeExtensionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNodeExtensionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNodeExtensionState(input string) (*NodeExtensionState, error) { + vals := map[string]NodeExtensionState{ + "accepted": NodeExtensionStateAccepted, + "canceled": NodeExtensionStateCanceled, + "connected": NodeExtensionStateConnected, + "creating": NodeExtensionStateCreating, + "deleted": NodeExtensionStateDeleted, + "deleting": NodeExtensionStateDeleting, + "disconnected": NodeExtensionStateDisconnected, + "error": NodeExtensionStateError, + "failed": NodeExtensionStateFailed, + "inprogress": NodeExtensionStateInProgress, + "moving": NodeExtensionStateMoving, + "notspecified": NodeExtensionStateNotSpecified, + "partiallyconnected": NodeExtensionStatePartiallyConnected, + "partiallysucceeded": NodeExtensionStatePartiallySucceeded, + "provisioning": NodeExtensionStateProvisioning, + "succeeded": NodeExtensionStateSucceeded, + "updating": NodeExtensionStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NodeExtensionState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateConnected ProvisioningState = "Connected" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateDisconnected ProvisioningState = "Disconnected" + ProvisioningStateError ProvisioningState = "Error" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStatePartiallyConnected ProvisioningState = "PartiallyConnected" + ProvisioningStatePartiallySucceeded ProvisioningState = "PartiallySucceeded" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateConnected), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateDisconnected), + string(ProvisioningStateError), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateMoving), + string(ProvisioningStateNotSpecified), + string(ProvisioningStatePartiallyConnected), + string(ProvisioningStatePartiallySucceeded), + string(ProvisioningStateProvisioning), + 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, + "connected": ProvisioningStateConnected, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "disconnected": ProvisioningStateDisconnected, + "error": ProvisioningStateError, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "moving": ProvisioningStateMoving, + "notspecified": ProvisioningStateNotSpecified, + "partiallyconnected": ProvisioningStatePartiallyConnected, + "partiallysucceeded": ProvisioningStatePartiallySucceeded, + "provisioning": ProvisioningStateProvisioning, + "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 StatusLevelTypes string + +const ( + StatusLevelTypesError StatusLevelTypes = "Error" + StatusLevelTypesInfo StatusLevelTypes = "Info" + StatusLevelTypesWarning StatusLevelTypes = "Warning" +) + +func PossibleValuesForStatusLevelTypes() []string { + return []string{ + string(StatusLevelTypesError), + string(StatusLevelTypesInfo), + string(StatusLevelTypesWarning), + } +} + +func (s *StatusLevelTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatusLevelTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatusLevelTypes(input string) (*StatusLevelTypes, error) { + vals := map[string]StatusLevelTypes{ + "error": StatusLevelTypesError, + "info": StatusLevelTypesInfo, + "warning": StatusLevelTypesWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StatusLevelTypes(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting.go new file mode 100644 index 00000000000..7621a47a878 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting.go @@ -0,0 +1,134 @@ +package extensions + +import ( + "fmt" + "strings" + + "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 = &ArcSettingId{} + +// ArcSettingId is a struct representing the Resource ID for a Arc Setting +type ArcSettingId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + ArcSettingName string +} + +// NewArcSettingID returns a new ArcSettingId struct +func NewArcSettingID(subscriptionId string, resourceGroupName string, clusterName string, arcSettingName string) ArcSettingId { + return ArcSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + ArcSettingName: arcSettingName, + } +} + +// ParseArcSettingID parses 'input' into a ArcSettingId +func ParseArcSettingID(input string) (*ArcSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArcSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArcSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseArcSettingIDInsensitively parses 'input' case-insensitively into a ArcSettingId +// note: this method should only be used for API response data and not user input +func ParseArcSettingIDInsensitively(input string) (*ArcSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArcSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArcSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ArcSettingId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.ArcSettingName, ok = input.Parsed["arcSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "arcSettingName", input) + } + + return nil +} + +// ValidateArcSettingID checks that 'input' can be parsed as a Arc Setting ID +func ValidateArcSettingID(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 := ParseArcSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Arc Setting ID +func (id ArcSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/arcSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.ArcSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Arc Setting ID +func (id ArcSettingId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticArcSettings", "arcSettings", "arcSettings"), + resourceids.UserSpecifiedSegment("arcSettingName", "arcSettingValue"), + } +} + +// String returns a human-readable description of this Arc Setting ID +func (id ArcSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Arc Setting Name: %q", id.ArcSettingName), + } + return fmt.Sprintf("Arc Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting_test.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting_test.go new file mode 100644 index 00000000000..b3bc46d3bc2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_arcsetting_test.go @@ -0,0 +1,327 @@ +package extensions + +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 = &ArcSettingId{} + +func TestNewArcSettingID(t *testing.T) { + id := NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.ArcSettingName != "arcSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ArcSettingName'", id.ArcSettingName, "arcSettingValue") + } +} + +func TestFormatArcSettingID(t *testing.T) { + actual := NewArcSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseArcSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArcSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArcSettingID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + } +} + +func TestParseArcSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArcSettingId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe", + Expected: &ArcSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + ArcSettingName: "aRcSeTtInGvAlUe", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArcSettingIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + } +} + +func TestSegmentsForArcSettingId(t *testing.T) { + segments := ArcSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ArcSettingId 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/azurestackhci/2023-08-01-preview/extensions/id_extension.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension.go new file mode 100644 index 00000000000..e18d01850cc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension.go @@ -0,0 +1,143 @@ +package extensions + +import ( + "fmt" + "strings" + + "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 = &ExtensionId{} + +// ExtensionId is a struct representing the Resource ID for a Extension +type ExtensionId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + ArcSettingName string + ExtensionName string +} + +// NewExtensionID returns a new ExtensionId struct +func NewExtensionID(subscriptionId string, resourceGroupName string, clusterName string, arcSettingName string, extensionName string) ExtensionId { + return ExtensionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + ArcSettingName: arcSettingName, + ExtensionName: extensionName, + } +} + +// ParseExtensionID parses 'input' into a ExtensionId +func ParseExtensionID(input string) (*ExtensionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExtensionIDInsensitively parses 'input' case-insensitively into a ExtensionId +// note: this method should only be used for API response data and not user input +func ParseExtensionIDInsensitively(input string) (*ExtensionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExtensionId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.ArcSettingName, ok = input.Parsed["arcSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "arcSettingName", input) + } + + if id.ExtensionName, ok = input.Parsed["extensionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "extensionName", input) + } + + return nil +} + +// ValidateExtensionID checks that 'input' can be parsed as a Extension ID +func ValidateExtensionID(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 := ParseExtensionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Extension ID +func (id ExtensionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/arcSettings/%s/extensions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.ArcSettingName, id.ExtensionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Extension ID +func (id ExtensionId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticArcSettings", "arcSettings", "arcSettings"), + resourceids.UserSpecifiedSegment("arcSettingName", "arcSettingValue"), + resourceids.StaticSegment("staticExtensions", "extensions", "extensions"), + resourceids.UserSpecifiedSegment("extensionName", "extensionValue"), + } +} + +// String returns a human-readable description of this Extension ID +func (id ExtensionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Arc Setting Name: %q", id.ArcSettingName), + fmt.Sprintf("Extension Name: %q", id.ExtensionName), + } + return fmt.Sprintf("Extension (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension_test.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension_test.go new file mode 100644 index 00000000000..bb42f56d91c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/id_extension_test.go @@ -0,0 +1,372 @@ +package extensions + +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 = &ExtensionId{} + +func TestNewExtensionID(t *testing.T) { + id := NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.ArcSettingName != "arcSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ArcSettingName'", id.ArcSettingName, "arcSettingValue") + } + + if id.ExtensionName != "extensionValue" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionName'", id.ExtensionName, "extensionValue") + } +} + +func TestFormatExtensionID(t *testing.T) { + actual := NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "arcSettingValue", "extensionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions/extensionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExtensionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions/extensionValue", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + ExtensionName: "extensionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions/extensionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + if actual.ExtensionName != v.Expected.ExtensionName { + t.Fatalf("Expected %q but got %q for ExtensionName", v.Expected.ExtensionName, actual.ExtensionName) + } + + } +} + +func TestParseExtensionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe/eXtEnSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions/extensionValue", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + ArcSettingName: "arcSettingValue", + ExtensionName: "extensionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/arcSettings/arcSettingValue/extensions/extensionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe/eXtEnSiOnS/eXtEnSiOnVaLuE", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + ArcSettingName: "aRcSeTtInGvAlUe", + ExtensionName: "eXtEnSiOnVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/aRcSeTtInGs/aRcSeTtInGvAlUe/eXtEnSiOnS/eXtEnSiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.ArcSettingName != v.Expected.ArcSettingName { + t.Fatalf("Expected %q but got %q for ArcSettingName", v.Expected.ArcSettingName, actual.ArcSettingName) + } + + if actual.ExtensionName != v.Expected.ExtensionName { + t.Fatalf("Expected %q but got %q for ExtensionName", v.Expected.ExtensionName, actual.ExtensionName) + } + + } +} + +func TestSegmentsForExtensionId(t *testing.T) { + segments := ExtensionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExtensionId 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/azurestackhci/2023-08-01-preview/extensions/method_create.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_create.go new file mode 100644 index 00000000000..272c77674e8 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_create.go @@ -0,0 +1,75 @@ +package extensions + +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 *Extension +} + +// Create ... +func (c ExtensionsClient) Create(ctx context.Context, id ExtensionId, input Extension) (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 ExtensionsClient) CreateThenPoll(ctx context.Context, id ExtensionId, input Extension) 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/azurestackhci/2023-08-01-preview/extensions/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_delete.go new file mode 100644 index 00000000000..00a5692b6d4 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_delete.go @@ -0,0 +1,71 @@ +package extensions + +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 ExtensionsClient) Delete(ctx context.Context, id ExtensionId) (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 ExtensionsClient) DeleteThenPoll(ctx context.Context, id ExtensionId) 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/azurestackhci/2023-08-01-preview/extensions/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_get.go new file mode 100644 index 00000000000..2555add1944 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_get.go @@ -0,0 +1,54 @@ +package extensions + +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 *Extension +} + +// Get ... +func (c ExtensionsClient) Get(ctx context.Context, id ExtensionId) (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 Extension + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_listbyarcsetting.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_listbyarcsetting.go new file mode 100644 index 00000000000..f92097a0588 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_listbyarcsetting.go @@ -0,0 +1,91 @@ +package extensions + +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 ListByArcSettingOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Extension +} + +type ListByArcSettingCompleteResult struct { + LatestHttpResponse *http.Response + Items []Extension +} + +// ListByArcSetting ... +func (c ExtensionsClient) ListByArcSetting(ctx context.Context, id ArcSettingId) (result ListByArcSettingOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extensions", 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 *[]Extension `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByArcSettingComplete retrieves all the results into a single object +func (c ExtensionsClient) ListByArcSettingComplete(ctx context.Context, id ArcSettingId) (ListByArcSettingCompleteResult, error) { + return c.ListByArcSettingCompleteMatchingPredicate(ctx, id, ExtensionOperationPredicate{}) +} + +// ListByArcSettingCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ExtensionsClient) ListByArcSettingCompleteMatchingPredicate(ctx context.Context, id ArcSettingId, predicate ExtensionOperationPredicate) (result ListByArcSettingCompleteResult, err error) { + items := make([]Extension, 0) + + resp, err := c.ListByArcSetting(ctx, id) + if err != nil { + 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 = ListByArcSettingCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_update.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_update.go new file mode 100644 index 00000000000..448e08ce7d8 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_update.go @@ -0,0 +1,75 @@ +package extensions + +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 *Extension +} + +// Update ... +func (c ExtensionsClient) Update(ctx context.Context, id ExtensionId, input ExtensionPatch) (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 ExtensionsClient) UpdateThenPoll(ctx context.Context, id ExtensionId, input ExtensionPatch) 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/azurestackhci/2023-08-01-preview/extensions/method_upgrade.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_upgrade.go new file mode 100644 index 00000000000..22d59b202cb --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/method_upgrade.go @@ -0,0 +1,73 @@ +package extensions + +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 UpgradeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Upgrade ... +func (c ExtensionsClient) Upgrade(ctx context.Context, id ExtensionId, input ExtensionUpgradeParameters) (result UpgradeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgrade", 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 +} + +// UpgradeThenPoll performs Upgrade then polls until it's completed +func (c ExtensionsClient) UpgradeThenPoll(ctx context.Context, id ExtensionId, input ExtensionUpgradeParameters) error { + result, err := c.Upgrade(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Upgrade: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Upgrade: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extension.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extension.go new file mode 100644 index 00000000000..7979b4827b5 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extension.go @@ -0,0 +1,16 @@ +package extensions + +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 Extension struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtensionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceview.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceview.go new file mode 100644 index 00000000000..8ef17ccd617 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceview.go @@ -0,0 +1,11 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionInstanceView struct { + Name *string `json:"name,omitempty"` + Status *ExtensionInstanceViewStatus `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceviewstatus.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceviewstatus.go new file mode 100644 index 00000000000..6af4bdef7ff --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensioninstanceviewstatus.go @@ -0,0 +1,30 @@ +package extensions + +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 ExtensionInstanceViewStatus struct { + Code *string `json:"code,omitempty"` + DisplayStatus *string `json:"displayStatus,omitempty"` + Level *StatusLevelTypes `json:"level,omitempty"` + Message *string `json:"message,omitempty"` + Time *string `json:"time,omitempty"` +} + +func (o *ExtensionInstanceViewStatus) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExtensionInstanceViewStatus) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionparameters.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionparameters.go new file mode 100644 index 00000000000..b267acba8cc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionparameters.go @@ -0,0 +1,15 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionParameters struct { + AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + ProtectedSettings *interface{} `json:"protectedSettings,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Settings *interface{} `json:"settings,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatch.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatch.go new file mode 100644 index 00000000000..a1640065bf9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatch.go @@ -0,0 +1,8 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionPatch struct { + Properties *ExtensionPatchProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchparameters.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchparameters.go new file mode 100644 index 00000000000..7ef03b42f20 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchparameters.go @@ -0,0 +1,11 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionPatchParameters struct { + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ProtectedSettings *interface{} `json:"protectedSettings,omitempty"` + Settings *interface{} `json:"settings,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchproperties.go new file mode 100644 index 00000000000..f4fea88c801 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionpatchproperties.go @@ -0,0 +1,8 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionPatchProperties struct { + ExtensionParameters *ExtensionPatchParameters `json:"extensionParameters,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionproperties.go new file mode 100644 index 00000000000..79e09cb07f2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionproperties.go @@ -0,0 +1,12 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionProperties struct { + AggregateState *ExtensionAggregateState `json:"aggregateState,omitempty"` + ExtensionParameters *ExtensionParameters `json:"extensionParameters,omitempty"` + ManagedBy *ExtensionManagedBy `json:"managedBy,omitempty"` + PerNodeExtensionDetails *[]PerNodeExtensionState `json:"perNodeExtensionDetails,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionupgradeparameters.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionupgradeparameters.go new file mode 100644 index 00000000000..7a45b84de73 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_extensionupgradeparameters.go @@ -0,0 +1,8 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionUpgradeParameters struct { + TargetVersion *string `json:"targetVersion,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_pernodeextensionstate.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_pernodeextensionstate.go new file mode 100644 index 00000000000..d60ad7ca9dc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/model_pernodeextensionstate.go @@ -0,0 +1,12 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PerNodeExtensionState struct { + Extension *string `json:"extension,omitempty"` + InstanceView *ExtensionInstanceView `json:"instanceView,omitempty"` + Name *string `json:"name,omitempty"` + State *NodeExtensionState `json:"state,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/extensions/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/predicates.go new file mode 100644 index 00000000000..41d2fee4d9b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/predicates.go @@ -0,0 +1,27 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtensionOperationPredicate) Matches(input Extension) 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/azurestackhci/2023-08-01-preview/extensions/version.go b/resource-manager/azurestackhci/2023-08-01-preview/extensions/version.go new file mode 100644 index 00000000000..a1d6badb871 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/extensions/version.go @@ -0,0 +1,12 @@ +package extensions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/extensions/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/README.md b/resource-manager/azurestackhci/2023-08-01-preview/offers/README.md new file mode 100644 index 00000000000..5936dba945b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/offers` Documentation + +The `offers` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/offers" +``` + + +### Client Initialization + +```go +client := offers.NewOffersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OffersClient.Get` + +```go +ctx := context.TODO() +id := offers.NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue") + +read, err := client.Get(ctx, id, offers.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `OffersClient.ListByCluster` + +```go +ctx := context.TODO() +id := offers.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// alternatively `client.ListByCluster(ctx, id, offers.DefaultListByClusterOperationOptions())` can be used to do batched pagination +items, err := client.ListByClusterComplete(ctx, id, offers.DefaultListByClusterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `OffersClient.ListByPublisher` + +```go +ctx := context.TODO() +id := offers.NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue") + +// alternatively `client.ListByPublisher(ctx, id, offers.DefaultListByPublisherOperationOptions())` can be used to do batched pagination +items, err := client.ListByPublisherComplete(ctx, id, offers.DefaultListByPublisherOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/client.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/client.go new file mode 100644 index 00000000000..77b5dddcd7b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/client.go @@ -0,0 +1,26 @@ +package offers + +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 OffersClient struct { + Client *resourcemanager.Client +} + +func NewOffersClientWithBaseURI(sdkApi sdkEnv.Api) (*OffersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "offers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OffersClient: %+v", err) + } + + return &OffersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster.go new file mode 100644 index 00000000000..145b0e1aba1 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster.go @@ -0,0 +1,125 @@ +package offers + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster_test.go new file mode 100644 index 00000000000..54aa1fe5b8e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_cluster_test.go @@ -0,0 +1,282 @@ +package offers + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/offers/id_offer.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer.go new file mode 100644 index 00000000000..195f5bea1a3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer.go @@ -0,0 +1,143 @@ +package offers + +import ( + "fmt" + "strings" + + "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 = &OfferId{} + +// OfferId is a struct representing the Resource ID for a Offer +type OfferId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + PublisherName string + OfferName string +} + +// NewOfferID returns a new OfferId struct +func NewOfferID(subscriptionId string, resourceGroupName string, clusterName string, publisherName string, offerName string) OfferId { + return OfferId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + PublisherName: publisherName, + OfferName: offerName, + } +} + +// ParseOfferID parses 'input' into a OfferId +func ParseOfferID(input string) (*OfferId, error) { + parser := resourceids.NewParserFromResourceIdType(&OfferId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OfferId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOfferIDInsensitively parses 'input' case-insensitively into a OfferId +// note: this method should only be used for API response data and not user input +func ParseOfferIDInsensitively(input string) (*OfferId, error) { + parser := resourceids.NewParserFromResourceIdType(&OfferId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OfferId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OfferId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.OfferName, ok = input.Parsed["offerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "offerName", input) + } + + return nil +} + +// ValidateOfferID checks that 'input' can be parsed as a Offer ID +func ValidateOfferID(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 := ParseOfferID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Offer ID +func (id OfferId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/publishers/%s/offers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.PublisherName, id.OfferName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Offer ID +func (id OfferId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherValue"), + resourceids.StaticSegment("staticOffers", "offers", "offers"), + resourceids.UserSpecifiedSegment("offerName", "offerValue"), + } +} + +// String returns a human-readable description of this Offer ID +func (id OfferId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Offer Name: %q", id.OfferName), + } + return fmt.Sprintf("Offer (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer_test.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer_test.go new file mode 100644 index 00000000000..19f11c58fd6 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_offer_test.go @@ -0,0 +1,372 @@ +package offers + +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 = &OfferId{} + +func TestNewOfferID(t *testing.T) { + id := NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.PublisherName != "publisherValue" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherValue") + } + + if id.OfferName != "offerValue" { + t.Fatalf("Expected %q but got %q for Segment 'OfferName'", id.OfferName, "offerValue") + } +} + +func TestFormatOfferID(t *testing.T) { + actual := NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOfferID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OfferId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOfferID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + } +} + +func TestParseOfferIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OfferId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + PublisherName: "pUbLiShErVaLuE", + OfferName: "oFfErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOfferIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + } +} + +func TestSegmentsForOfferId(t *testing.T) { + segments := OfferId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OfferId 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/azurestackhci/2023-08-01-preview/offers/id_publisher.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher.go new file mode 100644 index 00000000000..b0dcbe8a0b0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher.go @@ -0,0 +1,134 @@ +package offers + +import ( + "fmt" + "strings" + + "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 = &PublisherId{} + +// PublisherId is a struct representing the Resource ID for a Publisher +type PublisherId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + PublisherName string +} + +// NewPublisherID returns a new PublisherId struct +func NewPublisherID(subscriptionId string, resourceGroupName string, clusterName string, publisherName string) PublisherId { + return PublisherId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + PublisherName: publisherName, + } +} + +// ParsePublisherID parses 'input' into a PublisherId +func ParsePublisherID(input string) (*PublisherId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePublisherIDInsensitively parses 'input' case-insensitively into a PublisherId +// note: this method should only be used for API response data and not user input +func ParsePublisherIDInsensitively(input string) (*PublisherId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PublisherId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + return nil +} + +// ValidatePublisherID checks that 'input' can be parsed as a Publisher ID +func ValidatePublisherID(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 := ParsePublisherID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Publisher ID +func (id PublisherId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/publishers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.PublisherName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Publisher ID +func (id PublisherId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherValue"), + } +} + +// String returns a human-readable description of this Publisher ID +func (id PublisherId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + } + return fmt.Sprintf("Publisher (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher_test.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher_test.go new file mode 100644 index 00000000000..cbf8f7759e9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/id_publisher_test.go @@ -0,0 +1,327 @@ +package offers + +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 = &PublisherId{} + +func TestNewPublisherID(t *testing.T) { + id := NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.PublisherName != "publisherValue" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherValue") + } +} + +func TestFormatPublisherID(t *testing.T) { + actual := NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePublisherID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + } +} + +func TestParsePublisherIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + PublisherName: "pUbLiShErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + } +} + +func TestSegmentsForPublisherId(t *testing.T) { + segments := PublisherId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PublisherId 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/azurestackhci/2023-08-01-preview/offers/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_get.go new file mode 100644 index 00000000000..d23785a91f3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_get.go @@ -0,0 +1,83 @@ +package offers + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Offer +} + +type GetOperationOptions struct { + Expand *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c OffersClient) Get(ctx context.Context, id OfferId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + 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 Offer + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbycluster.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbycluster.go new file mode 100644 index 00000000000..3da0fcf6cbf --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbycluster.go @@ -0,0 +1,119 @@ +package offers + +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 ListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Offer +} + +type ListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Offer +} + +type ListByClusterOperationOptions struct { + Expand *string +} + +func DefaultListByClusterOperationOptions() ListByClusterOperationOptions { + return ListByClusterOperationOptions{} +} + +func (o ListByClusterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByClusterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByClusterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByCluster ... +func (c OffersClient) ListByCluster(ctx context.Context, id ClusterId, options ListByClusterOperationOptions) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/offers", id.ID()), + OptionsObject: options, + } + + 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 *[]Offer `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByClusterComplete retrieves all the results into a single object +func (c OffersClient) ListByClusterComplete(ctx context.Context, id ClusterId, options ListByClusterOperationOptions) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, options, OfferOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OffersClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id ClusterId, options ListByClusterOperationOptions, predicate OfferOperationPredicate) (result ListByClusterCompleteResult, err error) { + items := make([]Offer, 0) + + resp, err := c.ListByCluster(ctx, id, options) + if err != nil { + 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 = ListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbypublisher.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbypublisher.go new file mode 100644 index 00000000000..dde705ba35d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/method_listbypublisher.go @@ -0,0 +1,119 @@ +package offers + +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 ListByPublisherOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Offer +} + +type ListByPublisherCompleteResult struct { + LatestHttpResponse *http.Response + Items []Offer +} + +type ListByPublisherOperationOptions struct { + Expand *string +} + +func DefaultListByPublisherOperationOptions() ListByPublisherOperationOptions { + return ListByPublisherOperationOptions{} +} + +func (o ListByPublisherOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByPublisherOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByPublisherOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByPublisher ... +func (c OffersClient) ListByPublisher(ctx context.Context, id PublisherId, options ListByPublisherOperationOptions) (result ListByPublisherOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/offers", id.ID()), + OptionsObject: options, + } + + 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 *[]Offer `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPublisherComplete retrieves all the results into a single object +func (c OffersClient) ListByPublisherComplete(ctx context.Context, id PublisherId, options ListByPublisherOperationOptions) (ListByPublisherCompleteResult, error) { + return c.ListByPublisherCompleteMatchingPredicate(ctx, id, options, OfferOperationPredicate{}) +} + +// ListByPublisherCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OffersClient) ListByPublisherCompleteMatchingPredicate(ctx context.Context, id PublisherId, options ListByPublisherOperationOptions, predicate OfferOperationPredicate) (result ListByPublisherCompleteResult, err error) { + items := make([]Offer, 0) + + resp, err := c.ListByPublisher(ctx, id, options) + if err != nil { + 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 = ListByPublisherCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offer.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offer.go new file mode 100644 index 00000000000..e2c246d643b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offer.go @@ -0,0 +1,16 @@ +package offers + +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 Offer struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OfferProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offerproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offerproperties.go new file mode 100644 index 00000000000..a53c23229aa --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_offerproperties.go @@ -0,0 +1,12 @@ +package offers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OfferProperties struct { + Content *string `json:"content,omitempty"` + ContentVersion *string `json:"contentVersion,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublisherId *string `json:"publisherId,omitempty"` + SkuMappings *[]SkuMappings `json:"skuMappings,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/model_skumappings.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_skumappings.go new file mode 100644 index 00000000000..a2c8233a121 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/model_skumappings.go @@ -0,0 +1,10 @@ +package offers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuMappings struct { + CatalogPlanId *string `json:"catalogPlanId,omitempty"` + MarketplaceSkuId *string `json:"marketplaceSkuId,omitempty"` + MarketplaceSkuVersions *[]string `json:"marketplaceSkuVersions,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/offers/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/predicates.go new file mode 100644 index 00000000000..75da90fe272 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/predicates.go @@ -0,0 +1,27 @@ +package offers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OfferOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OfferOperationPredicate) Matches(input Offer) 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/azurestackhci/2023-08-01-preview/offers/version.go b/resource-manager/azurestackhci/2023-08-01-preview/offers/version.go new file mode 100644 index 00000000000..7ebcb6ca2de --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/offers/version.go @@ -0,0 +1,12 @@ +package offers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/offers/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/README.md b/resource-manager/azurestackhci/2023-08-01-preview/publishers/README.md new file mode 100644 index 00000000000..9d976ba9a6c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/publishers` Documentation + +The `publishers` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/publishers" +``` + + +### Client Initialization + +```go +client := publishers.NewPublishersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PublishersClient.Get` + +```go +ctx := context.TODO() +id := publishers.NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue") + +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: `PublishersClient.ListByCluster` + +```go +ctx := context.TODO() +id := publishers.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// alternatively `client.ListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/client.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/client.go new file mode 100644 index 00000000000..ea59faa9c8e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/client.go @@ -0,0 +1,26 @@ +package publishers + +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 PublishersClient struct { + Client *resourcemanager.Client +} + +func NewPublishersClientWithBaseURI(sdkApi sdkEnv.Api) (*PublishersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "publishers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PublishersClient: %+v", err) + } + + return &PublishersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster.go new file mode 100644 index 00000000000..74a373352ff --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster.go @@ -0,0 +1,125 @@ +package publishers + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster_test.go new file mode 100644 index 00000000000..282f6f51a1e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_cluster_test.go @@ -0,0 +1,282 @@ +package publishers + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/publishers/id_publisher.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher.go new file mode 100644 index 00000000000..e2086f39238 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher.go @@ -0,0 +1,134 @@ +package publishers + +import ( + "fmt" + "strings" + + "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 = &PublisherId{} + +// PublisherId is a struct representing the Resource ID for a Publisher +type PublisherId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + PublisherName string +} + +// NewPublisherID returns a new PublisherId struct +func NewPublisherID(subscriptionId string, resourceGroupName string, clusterName string, publisherName string) PublisherId { + return PublisherId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + PublisherName: publisherName, + } +} + +// ParsePublisherID parses 'input' into a PublisherId +func ParsePublisherID(input string) (*PublisherId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePublisherIDInsensitively parses 'input' case-insensitively into a PublisherId +// note: this method should only be used for API response data and not user input +func ParsePublisherIDInsensitively(input string) (*PublisherId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PublisherId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + return nil +} + +// ValidatePublisherID checks that 'input' can be parsed as a Publisher ID +func ValidatePublisherID(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 := ParsePublisherID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Publisher ID +func (id PublisherId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/publishers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.PublisherName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Publisher ID +func (id PublisherId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherValue"), + } +} + +// String returns a human-readable description of this Publisher ID +func (id PublisherId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + } + return fmt.Sprintf("Publisher (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher_test.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher_test.go new file mode 100644 index 00000000000..65a77ac1734 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/id_publisher_test.go @@ -0,0 +1,327 @@ +package publishers + +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 = &PublisherId{} + +func TestNewPublisherID(t *testing.T) { + id := NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.PublisherName != "publisherValue" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherValue") + } +} + +func TestFormatPublisherID(t *testing.T) { + actual := NewPublisherID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePublisherID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + } +} + +func TestParsePublisherIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE", + Expected: &PublisherId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + PublisherName: "pUbLiShErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + } +} + +func TestSegmentsForPublisherId(t *testing.T) { + segments := PublisherId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PublisherId 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/azurestackhci/2023-08-01-preview/publishers/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/method_get.go new file mode 100644 index 00000000000..850e3f895f2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/method_get.go @@ -0,0 +1,54 @@ +package publishers + +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 *Publisher +} + +// Get ... +func (c PublishersClient) Get(ctx context.Context, id PublisherId) (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 Publisher + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/method_listbycluster.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/method_listbycluster.go new file mode 100644 index 00000000000..afab97cd637 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/method_listbycluster.go @@ -0,0 +1,91 @@ +package publishers + +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 ListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Publisher +} + +type ListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Publisher +} + +// ListByCluster ... +func (c PublishersClient) ListByCluster(ctx context.Context, id ClusterId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/publishers", 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 *[]Publisher `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByClusterComplete retrieves all the results into a single object +func (c PublishersClient) ListByClusterComplete(ctx context.Context, id ClusterId) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, PublisherOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PublishersClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate PublisherOperationPredicate) (result ListByClusterCompleteResult, err error) { + items := make([]Publisher, 0) + + resp, err := c.ListByCluster(ctx, id) + if err != nil { + 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 = ListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisher.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisher.go new file mode 100644 index 00000000000..70fef995140 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisher.go @@ -0,0 +1,16 @@ +package publishers + +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 Publisher struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PublisherProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisherproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisherproperties.go new file mode 100644 index 00000000000..7aa30888f26 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/model_publisherproperties.go @@ -0,0 +1,8 @@ +package publishers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PublisherProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/publishers/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/predicates.go new file mode 100644 index 00000000000..efccddd2512 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/predicates.go @@ -0,0 +1,27 @@ +package publishers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PublisherOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PublisherOperationPredicate) Matches(input Publisher) 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/azurestackhci/2023-08-01-preview/publishers/version.go b/resource-manager/azurestackhci/2023-08-01-preview/publishers/version.go new file mode 100644 index 00000000000..d75a6944181 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/publishers/version.go @@ -0,0 +1,12 @@ +package publishers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/publishers/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/README.md b/resource-manager/azurestackhci/2023-08-01-preview/skuses/README.md new file mode 100644 index 00000000000..7f18442704c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/skuses` Documentation + +The `skuses` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/skuses" +``` + + +### Client Initialization + +```go +client := skuses.NewSkusesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SkusesClient.SkusGet` + +```go +ctx := context.TODO() +id := skuses.NewSkuID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue", "skuValue") + +read, err := client.SkusGet(ctx, id, skuses.DefaultSkusGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SkusesClient.SkusListByOffer` + +```go +ctx := context.TODO() +id := skuses.NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue") + +// alternatively `client.SkusListByOffer(ctx, id, skuses.DefaultSkusListByOfferOperationOptions())` can be used to do batched pagination +items, err := client.SkusListByOfferComplete(ctx, id, skuses.DefaultSkusListByOfferOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/client.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/client.go new file mode 100644 index 00000000000..85bd1abeccf --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/client.go @@ -0,0 +1,26 @@ +package skuses + +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 SkusesClient struct { + Client *resourcemanager.Client +} + +func NewSkusesClientWithBaseURI(sdkApi sdkEnv.Api) (*SkusesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "skuses", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SkusesClient: %+v", err) + } + + return &SkusesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer.go new file mode 100644 index 00000000000..6f8a5773101 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer.go @@ -0,0 +1,143 @@ +package skuses + +import ( + "fmt" + "strings" + + "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 = &OfferId{} + +// OfferId is a struct representing the Resource ID for a Offer +type OfferId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + PublisherName string + OfferName string +} + +// NewOfferID returns a new OfferId struct +func NewOfferID(subscriptionId string, resourceGroupName string, clusterName string, publisherName string, offerName string) OfferId { + return OfferId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + PublisherName: publisherName, + OfferName: offerName, + } +} + +// ParseOfferID parses 'input' into a OfferId +func ParseOfferID(input string) (*OfferId, error) { + parser := resourceids.NewParserFromResourceIdType(&OfferId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OfferId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOfferIDInsensitively parses 'input' case-insensitively into a OfferId +// note: this method should only be used for API response data and not user input +func ParseOfferIDInsensitively(input string) (*OfferId, error) { + parser := resourceids.NewParserFromResourceIdType(&OfferId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OfferId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OfferId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.OfferName, ok = input.Parsed["offerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "offerName", input) + } + + return nil +} + +// ValidateOfferID checks that 'input' can be parsed as a Offer ID +func ValidateOfferID(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 := ParseOfferID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Offer ID +func (id OfferId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/publishers/%s/offers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.PublisherName, id.OfferName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Offer ID +func (id OfferId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherValue"), + resourceids.StaticSegment("staticOffers", "offers", "offers"), + resourceids.UserSpecifiedSegment("offerName", "offerValue"), + } +} + +// String returns a human-readable description of this Offer ID +func (id OfferId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Offer Name: %q", id.OfferName), + } + return fmt.Sprintf("Offer (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer_test.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer_test.go new file mode 100644 index 00000000000..296f838b580 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_offer_test.go @@ -0,0 +1,372 @@ +package skuses + +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 = &OfferId{} + +func TestNewOfferID(t *testing.T) { + id := NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.PublisherName != "publisherValue" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherValue") + } + + if id.OfferName != "offerValue" { + t.Fatalf("Expected %q but got %q for Segment 'OfferName'", id.OfferName, "offerValue") + } +} + +func TestFormatOfferID(t *testing.T) { + actual := NewOfferID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOfferID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OfferId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOfferID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + } +} + +func TestParseOfferIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OfferId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE", + Expected: &OfferId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + PublisherName: "pUbLiShErVaLuE", + OfferName: "oFfErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOfferIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + } +} + +func TestSegmentsForOfferId(t *testing.T) { + segments := OfferId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OfferId 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/azurestackhci/2023-08-01-preview/skuses/id_sku.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku.go new file mode 100644 index 00000000000..ed83de74600 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku.go @@ -0,0 +1,152 @@ +package skuses + +import ( + "fmt" + "strings" + + "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 = &SkuId{} + +// SkuId is a struct representing the Resource ID for a Sku +type SkuId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + PublisherName string + OfferName string + SkuName string +} + +// NewSkuID returns a new SkuId struct +func NewSkuID(subscriptionId string, resourceGroupName string, clusterName string, publisherName string, offerName string, skuName string) SkuId { + return SkuId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + PublisherName: publisherName, + OfferName: offerName, + SkuName: skuName, + } +} + +// ParseSkuID parses 'input' into a SkuId +func ParseSkuID(input string) (*SkuId, error) { + parser := resourceids.NewParserFromResourceIdType(&SkuId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SkuId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSkuIDInsensitively parses 'input' case-insensitively into a SkuId +// note: this method should only be used for API response data and not user input +func ParseSkuIDInsensitively(input string) (*SkuId, error) { + parser := resourceids.NewParserFromResourceIdType(&SkuId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SkuId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SkuId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.OfferName, ok = input.Parsed["offerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "offerName", input) + } + + if id.SkuName, ok = input.Parsed["skuName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "skuName", input) + } + + return nil +} + +// ValidateSkuID checks that 'input' can be parsed as a Sku ID +func ValidateSkuID(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 := ParseSkuID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sku ID +func (id SkuId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/publishers/%s/offers/%s/skus/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.PublisherName, id.OfferName, id.SkuName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sku ID +func (id SkuId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherValue"), + resourceids.StaticSegment("staticOffers", "offers", "offers"), + resourceids.UserSpecifiedSegment("offerName", "offerValue"), + resourceids.StaticSegment("staticSkus", "skus", "skus"), + resourceids.UserSpecifiedSegment("skuName", "skuValue"), + } +} + +// String returns a human-readable description of this Sku ID +func (id SkuId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Offer Name: %q", id.OfferName), + fmt.Sprintf("Sku Name: %q", id.SkuName), + } + return fmt.Sprintf("Sku (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku_test.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku_test.go new file mode 100644 index 00000000000..3c8c14ebd3c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/id_sku_test.go @@ -0,0 +1,417 @@ +package skuses + +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 = &SkuId{} + +func TestNewSkuID(t *testing.T) { + id := NewSkuID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue", "skuValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.PublisherName != "publisherValue" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherValue") + } + + if id.OfferName != "offerValue" { + t.Fatalf("Expected %q but got %q for Segment 'OfferName'", id.OfferName, "offerValue") + } + + if id.SkuName != "skuValue" { + t.Fatalf("Expected %q but got %q for Segment 'SkuName'", id.SkuName, "skuValue") + } +} + +func TestFormatSkuID(t *testing.T) { + actual := NewSkuID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "publisherValue", "offerValue", "skuValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus/skuValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSkuID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SkuId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus/skuValue", + Expected: &SkuId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + SkuName: "skuValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus/skuValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSkuID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + if actual.SkuName != v.Expected.SkuName { + t.Fatalf("Expected %q but got %q for SkuName", v.Expected.SkuName, actual.SkuName) + } + + } +} + +func TestParseSkuIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SkuId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE/sKuS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus/skuValue", + Expected: &SkuId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + PublisherName: "publisherValue", + OfferName: "offerValue", + SkuName: "skuValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/publishers/publisherValue/offers/offerValue/skus/skuValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE/sKuS/sKuVaLuE", + Expected: &SkuId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + PublisherName: "pUbLiShErVaLuE", + OfferName: "oFfErVaLuE", + SkuName: "sKuVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/pUbLiShErS/pUbLiShErVaLuE/oFfErS/oFfErVaLuE/sKuS/sKuVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSkuIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.OfferName != v.Expected.OfferName { + t.Fatalf("Expected %q but got %q for OfferName", v.Expected.OfferName, actual.OfferName) + } + + if actual.SkuName != v.Expected.SkuName { + t.Fatalf("Expected %q but got %q for SkuName", v.Expected.SkuName, actual.SkuName) + } + + } +} + +func TestSegmentsForSkuId(t *testing.T) { + segments := SkuId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SkuId 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/azurestackhci/2023-08-01-preview/skuses/method_skusget.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skusget.go new file mode 100644 index 00000000000..5ae2a348d5b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skusget.go @@ -0,0 +1,83 @@ +package skuses + +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 SkusGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Sku +} + +type SkusGetOperationOptions struct { + Expand *string +} + +func DefaultSkusGetOperationOptions() SkusGetOperationOptions { + return SkusGetOperationOptions{} +} + +func (o SkusGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SkusGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SkusGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// SkusGet ... +func (c SkusesClient) SkusGet(ctx context.Context, id SkuId, options SkusGetOperationOptions) (result SkusGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + 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 Sku + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skuslistbyoffer.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skuslistbyoffer.go new file mode 100644 index 00000000000..b767e801788 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/method_skuslistbyoffer.go @@ -0,0 +1,119 @@ +package skuses + +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 SkusListByOfferOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Sku +} + +type SkusListByOfferCompleteResult struct { + LatestHttpResponse *http.Response + Items []Sku +} + +type SkusListByOfferOperationOptions struct { + Expand *string +} + +func DefaultSkusListByOfferOperationOptions() SkusListByOfferOperationOptions { + return SkusListByOfferOperationOptions{} +} + +func (o SkusListByOfferOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SkusListByOfferOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SkusListByOfferOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// SkusListByOffer ... +func (c SkusesClient) SkusListByOffer(ctx context.Context, id OfferId, options SkusListByOfferOperationOptions) (result SkusListByOfferOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/skus", id.ID()), + OptionsObject: options, + } + + 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 *[]Sku `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SkusListByOfferComplete retrieves all the results into a single object +func (c SkusesClient) SkusListByOfferComplete(ctx context.Context, id OfferId, options SkusListByOfferOperationOptions) (SkusListByOfferCompleteResult, error) { + return c.SkusListByOfferCompleteMatchingPredicate(ctx, id, options, SkuOperationPredicate{}) +} + +// SkusListByOfferCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SkusesClient) SkusListByOfferCompleteMatchingPredicate(ctx context.Context, id OfferId, options SkusListByOfferOperationOptions, predicate SkuOperationPredicate) (result SkusListByOfferCompleteResult, err error) { + items := make([]Sku, 0) + + resp, err := c.SkusListByOffer(ctx, id, options) + if err != nil { + 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 = SkusListByOfferCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_sku.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_sku.go new file mode 100644 index 00000000000..cef2062f1bb --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_sku.go @@ -0,0 +1,16 @@ +package skuses + +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 Sku struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SkuProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skumappings.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skumappings.go new file mode 100644 index 00000000000..fd05acdaf7d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skumappings.go @@ -0,0 +1,10 @@ +package skuses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuMappings struct { + CatalogPlanId *string `json:"catalogPlanId,omitempty"` + MarketplaceSkuId *string `json:"marketplaceSkuId,omitempty"` + MarketplaceSkuVersions *[]string `json:"marketplaceSkuVersions,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skuproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skuproperties.go new file mode 100644 index 00000000000..bc60d0aec34 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/model_skuproperties.go @@ -0,0 +1,13 @@ +package skuses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuProperties struct { + Content *string `json:"content,omitempty"` + ContentVersion *string `json:"contentVersion,omitempty"` + OfferId *string `json:"offerId,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublisherId *string `json:"publisherId,omitempty"` + SkuMappings *[]SkuMappings `json:"skuMappings,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/skuses/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/predicates.go new file mode 100644 index 00000000000..77c587da8fa --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/predicates.go @@ -0,0 +1,27 @@ +package skuses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SkuOperationPredicate) Matches(input Sku) 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/azurestackhci/2023-08-01-preview/skuses/version.go b/resource-manager/azurestackhci/2023-08-01-preview/skuses/version.go new file mode 100644 index 00000000000..4e405d68444 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/skuses/version.go @@ -0,0 +1,12 @@ +package skuses + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/skuses/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/README.md b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/README.md new file mode 100644 index 00000000000..eb8bd654d36 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updateruns` Documentation + +The `updateruns` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/updateruns" +``` + + +### Client Initialization + +```go +client := updateruns.NewUpdateRunsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UpdateRunsClient.Delete` + +```go +ctx := context.TODO() +id := updateruns.NewUpdateRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue", "updateRunValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `UpdateRunsClient.Get` + +```go +ctx := context.TODO() +id := updateruns.NewUpdateRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue", "updateRunValue") + +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: `UpdateRunsClient.List` + +```go +ctx := context.TODO() +id := updateruns.NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + +// 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: `UpdateRunsClient.Put` + +```go +ctx := context.TODO() +id := updateruns.NewUpdateRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue", "updateRunValue") + +payload := updateruns.UpdateRun{ + // ... +} + + +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/azurestackhci/2023-08-01-preview/updateruns/client.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/client.go new file mode 100644 index 00000000000..a5becca3c6b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/client.go @@ -0,0 +1,26 @@ +package updateruns + +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 UpdateRunsClient struct { + Client *resourcemanager.Client +} + +func NewUpdateRunsClientWithBaseURI(sdkApi sdkEnv.Api) (*UpdateRunsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "updateruns", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UpdateRunsClient: %+v", err) + } + + return &UpdateRunsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/constants.go new file mode 100644 index 00000000000..ff4039a367d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/constants.go @@ -0,0 +1,107 @@ +package updateruns + +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" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + } +} + +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, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + } + 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 UpdateRunPropertiesState string + +const ( + UpdateRunPropertiesStateFailed UpdateRunPropertiesState = "Failed" + UpdateRunPropertiesStateInProgress UpdateRunPropertiesState = "InProgress" + UpdateRunPropertiesStateSucceeded UpdateRunPropertiesState = "Succeeded" + UpdateRunPropertiesStateUnknown UpdateRunPropertiesState = "Unknown" +) + +func PossibleValuesForUpdateRunPropertiesState() []string { + return []string{ + string(UpdateRunPropertiesStateFailed), + string(UpdateRunPropertiesStateInProgress), + string(UpdateRunPropertiesStateSucceeded), + string(UpdateRunPropertiesStateUnknown), + } +} + +func (s *UpdateRunPropertiesState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateRunPropertiesState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUpdateRunPropertiesState(input string) (*UpdateRunPropertiesState, error) { + vals := map[string]UpdateRunPropertiesState{ + "failed": UpdateRunPropertiesStateFailed, + "inprogress": UpdateRunPropertiesStateInProgress, + "succeeded": UpdateRunPropertiesStateSucceeded, + "unknown": UpdateRunPropertiesStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateRunPropertiesState(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update.go new file mode 100644 index 00000000000..554e9423761 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update.go @@ -0,0 +1,134 @@ +package updateruns + +import ( + "fmt" + "strings" + + "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 = &UpdateId{} + +// UpdateId is a struct representing the Resource ID for a Update +type UpdateId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + UpdateName string +} + +// NewUpdateID returns a new UpdateId struct +func NewUpdateID(subscriptionId string, resourceGroupName string, clusterName string, updateName string) UpdateId { + return UpdateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + UpdateName: updateName, + } +} + +// ParseUpdateID parses 'input' into a UpdateId +func ParseUpdateID(input string) (*UpdateId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateIDInsensitively parses 'input' case-insensitively into a UpdateId +// note: this method should only be used for API response data and not user input +func ParseUpdateIDInsensitively(input string) (*UpdateId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.UpdateName, ok = input.Parsed["updateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateName", input) + } + + return nil +} + +// ValidateUpdateID checks that 'input' can be parsed as a Update ID +func ValidateUpdateID(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 := ParseUpdateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update ID +func (id UpdateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/updates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.UpdateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update ID +func (id UpdateId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticUpdates", "updates", "updates"), + resourceids.UserSpecifiedSegment("updateName", "updateValue"), + } +} + +// String returns a human-readable description of this Update ID +func (id UpdateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Update Name: %q", id.UpdateName), + } + return fmt.Sprintf("Update (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update_test.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update_test.go new file mode 100644 index 00000000000..d861fbd5428 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_update_test.go @@ -0,0 +1,327 @@ +package updateruns + +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 = &UpdateId{} + +func TestNewUpdateID(t *testing.T) { + id := NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.UpdateName != "updateValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateName'", id.UpdateName, "updateValue") + } +} + +func TestFormatUpdateID(t *testing.T) { + actual := NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + } +} + +func TestParseUpdateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + UpdateName: "uPdAtEvAlUe", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + } +} + +func TestSegmentsForUpdateId(t *testing.T) { + segments := UpdateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateId 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/azurestackhci/2023-08-01-preview/updateruns/id_updaterun.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun.go new file mode 100644 index 00000000000..23259bff193 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun.go @@ -0,0 +1,143 @@ +package updateruns + +import ( + "fmt" + "strings" + + "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 = &UpdateRunId{} + +// UpdateRunId is a struct representing the Resource ID for a Update Run +type UpdateRunId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + UpdateName string + UpdateRunName string +} + +// NewUpdateRunID returns a new UpdateRunId struct +func NewUpdateRunID(subscriptionId string, resourceGroupName string, clusterName string, updateName string, updateRunName string) UpdateRunId { + return UpdateRunId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + UpdateName: updateName, + UpdateRunName: updateRunName, + } +} + +// ParseUpdateRunID parses 'input' into a UpdateRunId +func ParseUpdateRunID(input string) (*UpdateRunId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateRunId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateRunId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateRunIDInsensitively parses 'input' case-insensitively into a UpdateRunId +// note: this method should only be used for API response data and not user input +func ParseUpdateRunIDInsensitively(input string) (*UpdateRunId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateRunId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateRunId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateRunId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.UpdateName, ok = input.Parsed["updateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateName", input) + } + + if id.UpdateRunName, ok = input.Parsed["updateRunName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateRunName", input) + } + + return nil +} + +// ValidateUpdateRunID checks that 'input' can be parsed as a Update Run ID +func ValidateUpdateRunID(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 := ParseUpdateRunID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Run ID +func (id UpdateRunId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/updates/%s/updateRuns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.UpdateName, id.UpdateRunName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Run ID +func (id UpdateRunId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticUpdates", "updates", "updates"), + resourceids.UserSpecifiedSegment("updateName", "updateValue"), + resourceids.StaticSegment("staticUpdateRuns", "updateRuns", "updateRuns"), + resourceids.UserSpecifiedSegment("updateRunName", "updateRunValue"), + } +} + +// String returns a human-readable description of this Update Run ID +func (id UpdateRunId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Update Name: %q", id.UpdateName), + fmt.Sprintf("Update Run Name: %q", id.UpdateRunName), + } + return fmt.Sprintf("Update Run (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun_test.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun_test.go new file mode 100644 index 00000000000..fa0b09aab3e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/id_updaterun_test.go @@ -0,0 +1,372 @@ +package updateruns + +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 = &UpdateRunId{} + +func TestNewUpdateRunID(t *testing.T) { + id := NewUpdateRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue", "updateRunValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.UpdateName != "updateValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateName'", id.UpdateName, "updateValue") + } + + if id.UpdateRunName != "updateRunValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateRunName'", id.UpdateRunName, "updateRunValue") + } +} + +func TestFormatUpdateRunID(t *testing.T) { + actual := NewUpdateRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue", "updateRunValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns/updateRunValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateRunID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateRunId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns/updateRunValue", + Expected: &UpdateRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + UpdateRunName: "updateRunValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns/updateRunValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateRunID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + if actual.UpdateRunName != v.Expected.UpdateRunName { + t.Fatalf("Expected %q but got %q for UpdateRunName", v.Expected.UpdateRunName, actual.UpdateRunName) + } + + } +} + +func TestParseUpdateRunIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateRunId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe/uPdAtErUnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns/updateRunValue", + Expected: &UpdateRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + UpdateRunName: "updateRunValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/updateRuns/updateRunValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe/uPdAtErUnS/uPdAtErUnVaLuE", + Expected: &UpdateRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + UpdateName: "uPdAtEvAlUe", + UpdateRunName: "uPdAtErUnVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe/uPdAtErUnS/uPdAtErUnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateRunIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + if actual.UpdateRunName != v.Expected.UpdateRunName { + t.Fatalf("Expected %q but got %q for UpdateRunName", v.Expected.UpdateRunName, actual.UpdateRunName) + } + + } +} + +func TestSegmentsForUpdateRunId(t *testing.T) { + segments := UpdateRunId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateRunId 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/azurestackhci/2023-08-01-preview/updateruns/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_delete.go new file mode 100644 index 00000000000..93881d05ad3 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_delete.go @@ -0,0 +1,71 @@ +package updateruns + +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 UpdateRunsClient) Delete(ctx context.Context, id UpdateRunId) (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 UpdateRunsClient) DeleteThenPoll(ctx context.Context, id UpdateRunId) 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/azurestackhci/2023-08-01-preview/updateruns/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_get.go new file mode 100644 index 00000000000..674bbb589e9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_get.go @@ -0,0 +1,54 @@ +package updateruns + +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 *UpdateRun +} + +// Get ... +func (c UpdateRunsClient) Get(ctx context.Context, id UpdateRunId) (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 UpdateRun + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_list.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_list.go new file mode 100644 index 00000000000..f530acd5f28 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_list.go @@ -0,0 +1,91 @@ +package updateruns + +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 *[]UpdateRun +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UpdateRun +} + +// List ... +func (c UpdateRunsClient) List(ctx context.Context, id UpdateId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updateRuns", 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 *[]UpdateRun `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 UpdateRunsClient) ListComplete(ctx context.Context, id UpdateId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UpdateRunOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UpdateRunsClient) ListCompleteMatchingPredicate(ctx context.Context, id UpdateId, predicate UpdateRunOperationPredicate) (result ListCompleteResult, err error) { + items := make([]UpdateRun, 0) + + resp, err := c.List(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/updateruns/method_put.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_put.go new file mode 100644 index 00000000000..58f21298c0f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/method_put.go @@ -0,0 +1,58 @@ +package updateruns + +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 *UpdateRun +} + +// Put ... +func (c UpdateRunsClient) Put(ctx context.Context, id UpdateRunId, input UpdateRun) (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 UpdateRun + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_step.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_step.go new file mode 100644 index 00000000000..ece5d657342 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_step.go @@ -0,0 +1,57 @@ +package updateruns + +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 Step struct { + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + LastUpdatedTimeUtc *string `json:"lastUpdatedTimeUtc,omitempty"` + Name *string `json:"name,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *string `json:"status,omitempty"` + Steps *[]Step `json:"steps,omitempty"` +} + +func (o *Step) GetEndTimeUtcAsTime() (*time.Time, error) { + if o.EndTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *Step) SetEndTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTimeUtc = &formatted +} + +func (o *Step) GetLastUpdatedTimeUtcAsTime() (*time.Time, error) { + if o.LastUpdatedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *Step) SetLastUpdatedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedTimeUtc = &formatted +} + +func (o *Step) GetStartTimeUtcAsTime() (*time.Time, error) { + if o.StartTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *Step) SetStartTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTimeUtc = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterun.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterun.go new file mode 100644 index 00000000000..d8fbe7ca6b7 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterun.go @@ -0,0 +1,17 @@ +package updateruns + +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 UpdateRun struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UpdateRunProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterunproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterunproperties.go new file mode 100644 index 00000000000..a2500945de0 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/model_updaterunproperties.go @@ -0,0 +1,43 @@ +package updateruns + +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 UpdateRunProperties struct { + Duration *string `json:"duration,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + Progress *Step `json:"progress,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + State *UpdateRunPropertiesState `json:"state,omitempty"` + TimeStarted *string `json:"timeStarted,omitempty"` +} + +func (o *UpdateRunProperties) GetLastUpdatedTimeAsTime() (*time.Time, error) { + if o.LastUpdatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateRunProperties) SetLastUpdatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedTime = &formatted +} + +func (o *UpdateRunProperties) GetTimeStartedAsTime() (*time.Time, error) { + if o.TimeStarted == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeStarted, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateRunProperties) SetTimeStartedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeStarted = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updateruns/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/predicates.go new file mode 100644 index 00000000000..3634b9136ba --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/predicates.go @@ -0,0 +1,32 @@ +package updateruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateRunOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p UpdateRunOperationPredicate) Matches(input UpdateRun) 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/azurestackhci/2023-08-01-preview/updateruns/version.go b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/version.go new file mode 100644 index 00000000000..4c835a70132 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updateruns/version.go @@ -0,0 +1,12 @@ +package updateruns + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/updateruns/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/README.md b/resource-manager/azurestackhci/2023-08-01-preview/updates/README.md new file mode 100644 index 00000000000..d60a7e18b1d --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/README.md @@ -0,0 +1,98 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updates` Documentation + +The `updates` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/updates" +``` + + +### Client Initialization + +```go +client := updates.NewUpdatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UpdatesClient.Delete` + +```go +ctx := context.TODO() +id := updates.NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `UpdatesClient.Get` + +```go +ctx := context.TODO() +id := updates.NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + +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: `UpdatesClient.List` + +```go +ctx := context.TODO() +id := updates.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// 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: `UpdatesClient.Post` + +```go +ctx := context.TODO() +id := updates.NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + +if err := client.PostThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `UpdatesClient.Put` + +```go +ctx := context.TODO() +id := updates.NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + +payload := updates.Update{ + // ... +} + + +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/azurestackhci/2023-08-01-preview/updates/client.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/client.go new file mode 100644 index 00000000000..f8438b80656 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/client.go @@ -0,0 +1,26 @@ +package updates + +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 UpdatesClient struct { + Client *resourcemanager.Client +} + +func NewUpdatesClientWithBaseURI(sdkApi sdkEnv.Api) (*UpdatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "updates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UpdatesClient: %+v", err) + } + + return &UpdatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/constants.go new file mode 100644 index 00000000000..648846294a9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/constants.go @@ -0,0 +1,381 @@ +package updates + +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 AvailabilityType string + +const ( + AvailabilityTypeLocal AvailabilityType = "Local" + AvailabilityTypeNotify AvailabilityType = "Notify" + AvailabilityTypeOnline AvailabilityType = "Online" +) + +func PossibleValuesForAvailabilityType() []string { + return []string{ + string(AvailabilityTypeLocal), + string(AvailabilityTypeNotify), + string(AvailabilityTypeOnline), + } +} + +func (s *AvailabilityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAvailabilityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAvailabilityType(input string) (*AvailabilityType, error) { + vals := map[string]AvailabilityType{ + "local": AvailabilityTypeLocal, + "notify": AvailabilityTypeNotify, + "online": AvailabilityTypeOnline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AvailabilityType(input) + return &out, nil +} + +type HealthState string + +const ( + HealthStateError HealthState = "Error" + HealthStateFailure HealthState = "Failure" + HealthStateInProgress HealthState = "InProgress" + HealthStateSuccess HealthState = "Success" + HealthStateUnknown HealthState = "Unknown" + HealthStateWarning HealthState = "Warning" +) + +func PossibleValuesForHealthState() []string { + return []string{ + string(HealthStateError), + string(HealthStateFailure), + string(HealthStateInProgress), + string(HealthStateSuccess), + string(HealthStateUnknown), + string(HealthStateWarning), + } +} + +func (s *HealthState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthState(input string) (*HealthState, error) { + vals := map[string]HealthState{ + "error": HealthStateError, + "failure": HealthStateFailure, + "inprogress": HealthStateInProgress, + "success": HealthStateSuccess, + "unknown": HealthStateUnknown, + "warning": HealthStateWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + } +} + +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, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + } + 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 RebootRequirement string + +const ( + RebootRequirementFalse RebootRequirement = "False" + RebootRequirementTrue RebootRequirement = "True" + RebootRequirementUnknown RebootRequirement = "Unknown" +) + +func PossibleValuesForRebootRequirement() []string { + return []string{ + string(RebootRequirementFalse), + string(RebootRequirementTrue), + string(RebootRequirementUnknown), + } +} + +func (s *RebootRequirement) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRebootRequirement(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRebootRequirement(input string) (*RebootRequirement, error) { + vals := map[string]RebootRequirement{ + "false": RebootRequirementFalse, + "true": RebootRequirementTrue, + "unknown": RebootRequirementUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RebootRequirement(input) + return &out, nil +} + +type Severity string + +const ( + SeverityCritical Severity = "Critical" + SeverityHidden Severity = "Hidden" + SeverityInformational Severity = "Informational" + SeverityWarning Severity = "Warning" +) + +func PossibleValuesForSeverity() []string { + return []string{ + string(SeverityCritical), + string(SeverityHidden), + string(SeverityInformational), + string(SeverityWarning), + } +} + +func (s *Severity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSeverity(input string) (*Severity, error) { + vals := map[string]Severity{ + "critical": SeverityCritical, + "hidden": SeverityHidden, + "informational": SeverityInformational, + "warning": SeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Severity(input) + return &out, nil +} + +type State string + +const ( + StateDownloadFailed State = "DownloadFailed" + StateDownloading State = "Downloading" + StateHasPrerequisite State = "HasPrerequisite" + StateHealthCheckFailed State = "HealthCheckFailed" + StateHealthChecking State = "HealthChecking" + StateInstallationFailed State = "InstallationFailed" + StateInstalled State = "Installed" + StateInstalling State = "Installing" + StateInvalid State = "Invalid" + StateNotApplicableBecauseAnotherUpdateIsInProgress State = "NotApplicableBecauseAnotherUpdateIsInProgress" + StateObsolete State = "Obsolete" + StatePreparationFailed State = "PreparationFailed" + StatePreparing State = "Preparing" + StateReady State = "Ready" + StateReadyToInstall State = "ReadyToInstall" + StateRecalled State = "Recalled" + StateScanFailed State = "ScanFailed" + StateScanInProgress State = "ScanInProgress" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateDownloadFailed), + string(StateDownloading), + string(StateHasPrerequisite), + string(StateHealthCheckFailed), + string(StateHealthChecking), + string(StateInstallationFailed), + string(StateInstalled), + string(StateInstalling), + string(StateInvalid), + string(StateNotApplicableBecauseAnotherUpdateIsInProgress), + string(StateObsolete), + string(StatePreparationFailed), + string(StatePreparing), + string(StateReady), + string(StateReadyToInstall), + string(StateRecalled), + string(StateScanFailed), + string(StateScanInProgress), + } +} + +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "downloadfailed": StateDownloadFailed, + "downloading": StateDownloading, + "hasprerequisite": StateHasPrerequisite, + "healthcheckfailed": StateHealthCheckFailed, + "healthchecking": StateHealthChecking, + "installationfailed": StateInstallationFailed, + "installed": StateInstalled, + "installing": StateInstalling, + "invalid": StateInvalid, + "notapplicablebecauseanotherupdateisinprogress": StateNotApplicableBecauseAnotherUpdateIsInProgress, + "obsolete": StateObsolete, + "preparationfailed": StatePreparationFailed, + "preparing": StatePreparing, + "ready": StateReady, + "readytoinstall": StateReadyToInstall, + "recalled": StateRecalled, + "scanfailed": StateScanFailed, + "scaninprogress": StateScanInProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} + +type Status string + +const ( + StatusFailed Status = "Failed" + StatusInProgress Status = "InProgress" + StatusSucceeded Status = "Succeeded" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusFailed), + string(StatusInProgress), + string(StatusSucceeded), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "failed": StatusFailed, + "inprogress": StatusInProgress, + "succeeded": StatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster.go new file mode 100644 index 00000000000..4d9dde23367 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster.go @@ -0,0 +1,125 @@ +package updates + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster_test.go new file mode 100644 index 00000000000..8555f39fa7e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_cluster_test.go @@ -0,0 +1,282 @@ +package updates + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/updates/id_update.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_update.go new file mode 100644 index 00000000000..abcab0ffd03 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_update.go @@ -0,0 +1,134 @@ +package updates + +import ( + "fmt" + "strings" + + "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 = &UpdateId{} + +// UpdateId is a struct representing the Resource ID for a Update +type UpdateId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string + UpdateName string +} + +// NewUpdateID returns a new UpdateId struct +func NewUpdateID(subscriptionId string, resourceGroupName string, clusterName string, updateName string) UpdateId { + return UpdateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + UpdateName: updateName, + } +} + +// ParseUpdateID parses 'input' into a UpdateId +func ParseUpdateID(input string) (*UpdateId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateIDInsensitively parses 'input' case-insensitively into a UpdateId +// note: this method should only be used for API response data and not user input +func ParseUpdateIDInsensitively(input string) (*UpdateId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + if id.UpdateName, ok = input.Parsed["updateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateName", input) + } + + return nil +} + +// ValidateUpdateID checks that 'input' can be parsed as a Update ID +func ValidateUpdateID(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 := ParseUpdateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update ID +func (id UpdateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s/updates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName, id.UpdateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update ID +func (id UpdateId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + resourceids.StaticSegment("staticUpdates", "updates", "updates"), + resourceids.UserSpecifiedSegment("updateName", "updateValue"), + } +} + +// String returns a human-readable description of this Update ID +func (id UpdateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + fmt.Sprintf("Update Name: %q", id.UpdateName), + } + return fmt.Sprintf("Update (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/id_update_test.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_update_test.go new file mode 100644 index 00000000000..a0c73c81ba2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/id_update_test.go @@ -0,0 +1,327 @@ +package updates + +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 = &UpdateId{} + +func TestNewUpdateID(t *testing.T) { + id := NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } + + if id.UpdateName != "updateValue" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateName'", id.UpdateName, "updateValue") + } +} + +func TestFormatUpdateID(t *testing.T) { + actual := NewUpdateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue", "updateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + } +} + +func TestParseUpdateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + UpdateName: "updateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/updates/updateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe", + Expected: &UpdateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + UpdateName: "uPdAtEvAlUe", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/uPdAtEs/uPdAtEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + if actual.UpdateName != v.Expected.UpdateName { + t.Fatalf("Expected %q but got %q for UpdateName", v.Expected.UpdateName, actual.UpdateName) + } + + } +} + +func TestSegmentsForUpdateId(t *testing.T) { + segments := UpdateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateId 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/azurestackhci/2023-08-01-preview/updates/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_delete.go new file mode 100644 index 00000000000..e2977fac7f9 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_delete.go @@ -0,0 +1,71 @@ +package updates + +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 UpdatesClient) Delete(ctx context.Context, id UpdateId) (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 UpdatesClient) DeleteThenPoll(ctx context.Context, id UpdateId) 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/azurestackhci/2023-08-01-preview/updates/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_get.go new file mode 100644 index 00000000000..7608d9b1fdd --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_get.go @@ -0,0 +1,54 @@ +package updates + +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 *Update +} + +// Get ... +func (c UpdatesClient) Get(ctx context.Context, id UpdateId) (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 Update + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/method_list.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_list.go new file mode 100644 index 00000000000..c0ef9b34fe6 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_list.go @@ -0,0 +1,91 @@ +package updates + +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 *[]Update +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Update +} + +// List ... +func (c UpdatesClient) List(ctx context.Context, id ClusterId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updates", 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 *[]Update `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 UpdatesClient) ListComplete(ctx context.Context, id ClusterId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UpdateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UpdatesClient) ListCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate UpdateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Update, 0) + + resp, err := c.List(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/updates/method_post.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_post.go new file mode 100644 index 00000000000..b41ccb849bb --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_post.go @@ -0,0 +1,70 @@ +package updates + +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 PostOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Post ... +func (c UpdatesClient) Post(ctx context.Context, id UpdateId) (result PostOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/apply", 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 +} + +// PostThenPoll performs Post then polls until it's completed +func (c UpdatesClient) PostThenPoll(ctx context.Context, id UpdateId) error { + result, err := c.Post(ctx, id) + if err != nil { + return fmt.Errorf("performing Post: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Post: %+v", err) + } + + return nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/method_put.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_put.go new file mode 100644 index 00000000000..1da3ed2ae54 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/method_put.go @@ -0,0 +1,58 @@ +package updates + +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 *Update +} + +// Put ... +func (c UpdatesClient) Put(ctx context.Context, id UpdateId, input Update) (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 Update + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_packageversioninfo.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_packageversioninfo.go new file mode 100644 index 00000000000..2376b23ed11 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_packageversioninfo.go @@ -0,0 +1,28 @@ +package updates + +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 PackageVersionInfo struct { + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageType *string `json:"packageType,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *PackageVersionInfo) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *PackageVersionInfo) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresult.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresult.go new file mode 100644 index 00000000000..22b924a1d10 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresult.go @@ -0,0 +1,37 @@ +package updates + +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 PrecheckResult struct { + AdditionalData *string `json:"additionalData,omitempty"` + Description *string `json:"description,omitempty"` + HealthCheckSource *string `json:"healthCheckSource,omitempty"` + Name *string `json:"name,omitempty"` + Remediation *string `json:"remediation,omitempty"` + Severity *Severity `json:"severity,omitempty"` + Status *Status `json:"status,omitempty"` + Tags *PrecheckResultTags `json:"tags,omitempty"` + TargetResourceID *string `json:"targetResourceID,omitempty"` + TargetResourceName *string `json:"targetResourceName,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + Title *string `json:"title,omitempty"` +} + +func (o *PrecheckResult) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *PrecheckResult) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresulttags.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresulttags.go new file mode 100644 index 00000000000..eac41de78dc --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_precheckresulttags.go @@ -0,0 +1,9 @@ +package updates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrecheckResultTags struct { + Key *string `json:"key,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_update.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_update.go new file mode 100644 index 00000000000..c5722f69cb2 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_update.go @@ -0,0 +1,17 @@ +package updates + +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 Update struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UpdateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateprerequisite.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateprerequisite.go new file mode 100644 index 00000000000..42904efc591 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateprerequisite.go @@ -0,0 +1,10 @@ +package updates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdatePrerequisite struct { + PackageName *string `json:"packageName,omitempty"` + UpdateType *string `json:"updateType,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateproperties.go new file mode 100644 index 00000000000..7c2ffff7e51 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updateproperties.go @@ -0,0 +1,57 @@ +package updates + +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 UpdateProperties struct { + AdditionalProperties *string `json:"additionalProperties,omitempty"` + AvailabilityType *AvailabilityType `json:"availabilityType,omitempty"` + ComponentVersions *[]PackageVersionInfo `json:"componentVersions,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + HealthCheckDate *string `json:"healthCheckDate,omitempty"` + HealthCheckResult *[]PrecheckResult `json:"healthCheckResult,omitempty"` + HealthState *HealthState `json:"healthState,omitempty"` + InstalledDate *string `json:"installedDate,omitempty"` + PackagePath *string `json:"packagePath,omitempty"` + PackageSizeInMb *float64 `json:"packageSizeInMb,omitempty"` + PackageType *string `json:"packageType,omitempty"` + Prerequisites *[]UpdatePrerequisite `json:"prerequisites,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Publisher *string `json:"publisher,omitempty"` + RebootRequired *RebootRequirement `json:"rebootRequired,omitempty"` + ReleaseLink *string `json:"releaseLink,omitempty"` + State *State `json:"state,omitempty"` + UpdateStateProperties *UpdateStateProperties `json:"updateStateProperties,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *UpdateProperties) GetHealthCheckDateAsTime() (*time.Time, error) { + if o.HealthCheckDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.HealthCheckDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateProperties) SetHealthCheckDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.HealthCheckDate = &formatted +} + +func (o *UpdateProperties) GetInstalledDateAsTime() (*time.Time, error) { + if o.InstalledDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.InstalledDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateProperties) SetInstalledDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.InstalledDate = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updatestateproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updatestateproperties.go new file mode 100644 index 00000000000..4a17ca955a8 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/model_updatestateproperties.go @@ -0,0 +1,9 @@ +package updates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateStateProperties struct { + NotifyMessage *string `json:"notifyMessage,omitempty"` + ProgressPercentage *float64 `json:"progressPercentage,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updates/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/predicates.go new file mode 100644 index 00000000000..d64c5b9063f --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/predicates.go @@ -0,0 +1,32 @@ +package updates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p UpdateOperationPredicate) Matches(input Update) 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/azurestackhci/2023-08-01-preview/updates/version.go b/resource-manager/azurestackhci/2023-08-01-preview/updates/version.go new file mode 100644 index 00000000000..578234a3474 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updates/version.go @@ -0,0 +1,12 @@ +package updates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/updates/%s", defaultApiVersion) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/README.md b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/README.md new file mode 100644 index 00000000000..e63f282d7d7 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries` Documentation + +The `updatesummaries` SDK allows for interaction with the Azure Resource Manager Service `azurestackhci` (API Version `2023-08-01-preview`). + +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/azurestackhci/2023-08-01-preview/updatesummaries" +``` + + +### Client Initialization + +```go +client := updatesummaries.NewUpdateSummariesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UpdateSummariesClient.Delete` + +```go +ctx := context.TODO() +id := updatesummaries.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `UpdateSummariesClient.Get` + +```go +ctx := context.TODO() +id := updatesummaries.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +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: `UpdateSummariesClient.List` + +```go +ctx := context.TODO() +id := updatesummaries.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +// 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: `UpdateSummariesClient.Put` + +```go +ctx := context.TODO() +id := updatesummaries.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + +payload := updatesummaries.UpdateSummaries{ + // ... +} + + +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/azurestackhci/2023-08-01-preview/updatesummaries/client.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/client.go new file mode 100644 index 00000000000..869223878e1 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/client.go @@ -0,0 +1,26 @@ +package updatesummaries + +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 UpdateSummariesClient struct { + Client *resourcemanager.Client +} + +func NewUpdateSummariesClientWithBaseURI(sdkApi sdkEnv.Api) (*UpdateSummariesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "updatesummaries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UpdateSummariesClient: %+v", err) + } + + return &UpdateSummariesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/constants.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/constants.go new file mode 100644 index 00000000000..ddc5ca86b5c --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/constants.go @@ -0,0 +1,263 @@ +package updatesummaries + +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 HealthState string + +const ( + HealthStateError HealthState = "Error" + HealthStateFailure HealthState = "Failure" + HealthStateInProgress HealthState = "InProgress" + HealthStateSuccess HealthState = "Success" + HealthStateUnknown HealthState = "Unknown" + HealthStateWarning HealthState = "Warning" +) + +func PossibleValuesForHealthState() []string { + return []string{ + string(HealthStateError), + string(HealthStateFailure), + string(HealthStateInProgress), + string(HealthStateSuccess), + string(HealthStateUnknown), + string(HealthStateWarning), + } +} + +func (s *HealthState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthState(input string) (*HealthState, error) { + vals := map[string]HealthState{ + "error": HealthStateError, + "failure": HealthStateFailure, + "inprogress": HealthStateInProgress, + "success": HealthStateSuccess, + "unknown": HealthStateUnknown, + "warning": HealthStateWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + } +} + +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, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + } + 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 Severity string + +const ( + SeverityCritical Severity = "Critical" + SeverityHidden Severity = "Hidden" + SeverityInformational Severity = "Informational" + SeverityWarning Severity = "Warning" +) + +func PossibleValuesForSeverity() []string { + return []string{ + string(SeverityCritical), + string(SeverityHidden), + string(SeverityInformational), + string(SeverityWarning), + } +} + +func (s *Severity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSeverity(input string) (*Severity, error) { + vals := map[string]Severity{ + "critical": SeverityCritical, + "hidden": SeverityHidden, + "informational": SeverityInformational, + "warning": SeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Severity(input) + return &out, nil +} + +type Status string + +const ( + StatusFailed Status = "Failed" + StatusInProgress Status = "InProgress" + StatusSucceeded Status = "Succeeded" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusFailed), + string(StatusInProgress), + string(StatusSucceeded), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "failed": StatusFailed, + "inprogress": StatusInProgress, + "succeeded": StatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type UpdateSummariesPropertiesState string + +const ( + UpdateSummariesPropertiesStateAppliedSuccessfully UpdateSummariesPropertiesState = "AppliedSuccessfully" + UpdateSummariesPropertiesStateNeedsAttention UpdateSummariesPropertiesState = "NeedsAttention" + UpdateSummariesPropertiesStatePreparationFailed UpdateSummariesPropertiesState = "PreparationFailed" + UpdateSummariesPropertiesStatePreparationInProgress UpdateSummariesPropertiesState = "PreparationInProgress" + UpdateSummariesPropertiesStateUnknown UpdateSummariesPropertiesState = "Unknown" + UpdateSummariesPropertiesStateUpdateAvailable UpdateSummariesPropertiesState = "UpdateAvailable" + UpdateSummariesPropertiesStateUpdateFailed UpdateSummariesPropertiesState = "UpdateFailed" + UpdateSummariesPropertiesStateUpdateInProgress UpdateSummariesPropertiesState = "UpdateInProgress" +) + +func PossibleValuesForUpdateSummariesPropertiesState() []string { + return []string{ + string(UpdateSummariesPropertiesStateAppliedSuccessfully), + string(UpdateSummariesPropertiesStateNeedsAttention), + string(UpdateSummariesPropertiesStatePreparationFailed), + string(UpdateSummariesPropertiesStatePreparationInProgress), + string(UpdateSummariesPropertiesStateUnknown), + string(UpdateSummariesPropertiesStateUpdateAvailable), + string(UpdateSummariesPropertiesStateUpdateFailed), + string(UpdateSummariesPropertiesStateUpdateInProgress), + } +} + +func (s *UpdateSummariesPropertiesState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateSummariesPropertiesState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUpdateSummariesPropertiesState(input string) (*UpdateSummariesPropertiesState, error) { + vals := map[string]UpdateSummariesPropertiesState{ + "appliedsuccessfully": UpdateSummariesPropertiesStateAppliedSuccessfully, + "needsattention": UpdateSummariesPropertiesStateNeedsAttention, + "preparationfailed": UpdateSummariesPropertiesStatePreparationFailed, + "preparationinprogress": UpdateSummariesPropertiesStatePreparationInProgress, + "unknown": UpdateSummariesPropertiesStateUnknown, + "updateavailable": UpdateSummariesPropertiesStateUpdateAvailable, + "updatefailed": UpdateSummariesPropertiesStateUpdateFailed, + "updateinprogress": UpdateSummariesPropertiesStateUpdateInProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateSummariesPropertiesState(input) + return &out, nil +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster.go new file mode 100644 index 00000000000..37d9dd06b82 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster.go @@ -0,0 +1,125 @@ +package updatesummaries + +import ( + "fmt" + "strings" + + "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 = &ClusterId{} + +// ClusterId is a struct representing the Resource ID for a Cluster +type ClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewClusterID returns a new ClusterId struct +func NewClusterID(subscriptionId string, resourceGroupName string, clusterName string) ClusterId { + return ClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseClusterID parses 'input' into a ClusterId +func ParseClusterID(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClusterIDInsensitively parses 'input' case-insensitively into a ClusterId +// note: this method should only be used for API response data and not user input +func ParseClusterIDInsensitively(input string) (*ClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClusterId) 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.ClusterName, ok = input.Parsed["clusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clusterName", input) + } + + return nil +} + +// ValidateClusterID checks that 'input' can be parsed as a Cluster ID +func ValidateClusterID(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 := ParseClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cluster ID +func (id ClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHCI/clusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cluster ID +func (id ClusterId) 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("staticMicrosoftAzureStackHCI", "Microsoft.AzureStackHCI", "Microsoft.AzureStackHCI"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Cluster ID +func (id ClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster_test.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster_test.go new file mode 100644 index 00000000000..6e7ce084f3a --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/id_cluster_test.go @@ -0,0 +1,282 @@ +package updatesummaries + +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 = &ClusterId{} + +func TestNewClusterID(t *testing.T) { + id := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + 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.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterID(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClusterId + }{ + { + // 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.AzureStackHCI", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.AzureStackHCI/clusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // 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.aZuReStAcKhCi/cLuStErS/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClusterIDInsensitively(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.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForClusterId(t *testing.T) { + segments := ClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClusterId 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/azurestackhci/2023-08-01-preview/updatesummaries/method_delete.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_delete.go new file mode 100644 index 00000000000..b3ba841c6be --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_delete.go @@ -0,0 +1,71 @@ +package updatesummaries + +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 UpdateSummariesClient) Delete(ctx context.Context, id ClusterId) (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: fmt.Sprintf("%s/updateSummaries/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c UpdateSummariesClient) DeleteThenPoll(ctx context.Context, id ClusterId) 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/azurestackhci/2023-08-01-preview/updatesummaries/method_get.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_get.go new file mode 100644 index 00000000000..874fcd2d831 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_get.go @@ -0,0 +1,55 @@ +package updatesummaries + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UpdateSummaries +} + +// Get ... +func (c UpdateSummariesClient) Get(ctx context.Context, id ClusterId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updateSummaries/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 UpdateSummaries + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_list.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_list.go new file mode 100644 index 00000000000..59c86bf4570 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_list.go @@ -0,0 +1,91 @@ +package updatesummaries + +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 *[]UpdateSummaries +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UpdateSummaries +} + +// List ... +func (c UpdateSummariesClient) List(ctx context.Context, id ClusterId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/updateSummaries", 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 *[]UpdateSummaries `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 UpdateSummariesClient) ListComplete(ctx context.Context, id ClusterId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UpdateSummariesOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UpdateSummariesClient) ListCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate UpdateSummariesOperationPredicate) (result ListCompleteResult, err error) { + items := make([]UpdateSummaries, 0) + + resp, err := c.List(ctx, id) + if err != nil { + 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/azurestackhci/2023-08-01-preview/updatesummaries/method_put.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_put.go new file mode 100644 index 00000000000..a8b151c8e57 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/method_put.go @@ -0,0 +1,59 @@ +package updatesummaries + +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 PutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UpdateSummaries +} + +// Put ... +func (c UpdateSummariesClient) Put(ctx context.Context, id ClusterId, input UpdateSummaries) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/updateSummaries/default", 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 UpdateSummaries + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_packageversioninfo.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_packageversioninfo.go new file mode 100644 index 00000000000..33735a82452 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_packageversioninfo.go @@ -0,0 +1,28 @@ +package updatesummaries + +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 PackageVersionInfo struct { + LastUpdated *string `json:"lastUpdated,omitempty"` + PackageType *string `json:"packageType,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *PackageVersionInfo) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *PackageVersionInfo) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresult.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresult.go new file mode 100644 index 00000000000..877f1918f9e --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresult.go @@ -0,0 +1,37 @@ +package updatesummaries + +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 PrecheckResult struct { + AdditionalData *string `json:"additionalData,omitempty"` + Description *string `json:"description,omitempty"` + HealthCheckSource *string `json:"healthCheckSource,omitempty"` + Name *string `json:"name,omitempty"` + Remediation *string `json:"remediation,omitempty"` + Severity *Severity `json:"severity,omitempty"` + Status *Status `json:"status,omitempty"` + Tags *PrecheckResultTags `json:"tags,omitempty"` + TargetResourceID *string `json:"targetResourceID,omitempty"` + TargetResourceName *string `json:"targetResourceName,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + Title *string `json:"title,omitempty"` +} + +func (o *PrecheckResult) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *PrecheckResult) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresulttags.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresulttags.go new file mode 100644 index 00000000000..4dffe374f28 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_precheckresulttags.go @@ -0,0 +1,9 @@ +package updatesummaries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrecheckResultTags struct { + Key *string `json:"key,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummaries.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummaries.go new file mode 100644 index 00000000000..2c73541f2ed --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummaries.go @@ -0,0 +1,17 @@ +package updatesummaries + +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 UpdateSummaries struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UpdateSummariesProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummariesproperties.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummariesproperties.go new file mode 100644 index 00000000000..f6a0a7b4441 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/model_updatesummariesproperties.go @@ -0,0 +1,60 @@ +package updatesummaries + +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 UpdateSummariesProperties struct { + CurrentVersion *string `json:"currentVersion,omitempty"` + HardwareModel *string `json:"hardwareModel,omitempty"` + HealthCheckDate *string `json:"healthCheckDate,omitempty"` + HealthCheckResult *[]PrecheckResult `json:"healthCheckResult,omitempty"` + HealthState *HealthState `json:"healthState,omitempty"` + LastChecked *string `json:"lastChecked,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + OemFamily *string `json:"oemFamily,omitempty"` + PackageVersions *[]PackageVersionInfo `json:"packageVersions,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + State *UpdateSummariesPropertiesState `json:"state,omitempty"` +} + +func (o *UpdateSummariesProperties) GetHealthCheckDateAsTime() (*time.Time, error) { + if o.HealthCheckDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.HealthCheckDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateSummariesProperties) SetHealthCheckDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.HealthCheckDate = &formatted +} + +func (o *UpdateSummariesProperties) GetLastCheckedAsTime() (*time.Time, error) { + if o.LastChecked == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastChecked, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateSummariesProperties) SetLastCheckedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastChecked = &formatted +} + +func (o *UpdateSummariesProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpdateSummariesProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/predicates.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/predicates.go new file mode 100644 index 00000000000..ec256ccef50 --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/predicates.go @@ -0,0 +1,32 @@ +package updatesummaries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateSummariesOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p UpdateSummariesOperationPredicate) Matches(input UpdateSummaries) 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/azurestackhci/2023-08-01-preview/updatesummaries/version.go b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/version.go new file mode 100644 index 00000000000..ed77687702b --- /dev/null +++ b/resource-manager/azurestackhci/2023-08-01-preview/updatesummaries/version.go @@ -0,0 +1,12 @@ +package updatesummaries + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/updatesummaries/%s", defaultApiVersion) +}